Cod sursa(job #1981602)

Utilizator cyg_CiuntuSorinCiuntu Sorin Andrei cyg_CiuntuSorin Data 16 mai 2017 10:40:45
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const double INF=2.e9;
struct POINT
{
	int x,y;
};
vector<POINT>v;
vector<double>p;
bool vertical(POINT A,POINT B)
{
	return A.x==B.x;
}
double panta(POINT A,POINT B)
{
	if (vertical(A,B))
		return INF;
	else
			return (1.0*B.y-A.y)/(B.x-A.x);
}
int main()
{
		//freopen ("trapez.in","r",stdin);
		//freopen ("trapez.out","w",stdout);
		int n,i,j,a,b,r;
		r=0;
		POINT temp;
		scanf ("%d",&n);
		for (i=1;i<=n;i++)
		{
			scanf ("%d %d",&a,&b);
			temp.x=a;
			temp.y=b;
			v.push_back(temp);
		}
		for (i=0;i<n-1;i++)
			for (j=i+1;j<=n-1;j++)
				p.push_back(panta(v[i],v[j]));
		sort (p.begin(),p.end());
		for (i=1;i<n-1;i++)
			if (p[i]==p[i+1])
				r++;
		printf ("%d",r);
    return 0;
}