Cod sursa(job #345819)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 4 septembrie 2009 21:10:06
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 1024
#define M 500502
const double eps = (double)0.000000000001;
struct trapez{int x,y;}v[N];
int n;
double p[M];
long long num=0,dr=0;
bool compar(const double  &a,const double &b)
{
	return a-b<eps;
}
void citire()
{
	freopen("trapez.in","r",stdin);
	freopen("trapez.out","w",stdout);
	scanf("%d",&n);
	for (short int i=1; i<=n; ++i)
		scanf("%d%d",&v[i].x,&v[i].y);
}
void gasesc()
{
	for (short int i=1; i<n; ++i)
		for (short int j=i+1; j<=n; ++j)
			if (v[i].x!=v[j].x)
				p[++num]=(double)(v[i].y-v[j].y)/(v[i].x-v[j].x);
			else
				++dr;
	sort(p+1,p+1+num,compar);
	n=num;
	num=1;
	dr=dr*(dr-1)/2;
	short int i=1;
	for ( i=1;i<n; ++i)
		if (p[i+1]-p[i]<eps)
			++num;
		else
		{
			dr+=num*(num-1)/2;
			num=1;
		}
	dr+=num*(num-1)/2;
	printf("%lld",dr);
}
int main()
{
	citire();
	gasesc();
	return 0;
}