Cod sursa(job #810670)

Utilizator smaraldaSmaranda Dinu smaralda Data 10 noiembrie 2012 18:45:34
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include<stdio.h>
#include<math.h>
#define eps 1e-14
#define inf 2000000000
#include<vector>
#include<algorithm>
using namespace std;
struct POINT  { int  x, y; };
double tg[1000100];
vector <POINT> p;
double panta(POINT a,POINT b)
{
	if(fabs(b.x-a.x)<eps) return inf;
	return (double)(double(b.y-a.y)/(b.x-a.x));
}

bool cmp(double a, double b)
{
	return a-b<-eps;
}

int main()
{
	freopen("trapez.in","r",stdin);
	freopen("trapez.out","w",stdout);
	int i,n,j,temp1,k,temp2,l,rez;
	POINT temp;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		{
			scanf("%d%d",&temp1,&temp2);
			temp.x=temp1; temp.y=temp2;
			p.push_back(temp);
		}
	k=-1;
	for(i=0;i<p.size();i++)
		for(j=0;j<i;j++)
			tg[++k]=panta(p[i],p[j]);
	sort(tg,tg+k,cmp);
	tg[++k]=-inf;
	l=1;
	rez=0;
	for(i=0;i<k;i++)
		if(fabs(tg[i+1]-tg[i])<eps)
			l++;
		else
			{
				rez+=l*(l-1)/2;
				l=1;
			}
	printf("%d\n",rez);
	return 0;
}