Cod sursa(job #343766)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 27 august 2009 11:23:40
Problema Trapez Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 1024
#define M 500501
struct trapez{long long x,y;}v[N];
short int n;
double p[M];
long long num=0,dr=0;
bool compar(const double &a,const double&b)
{
	return a<b;
}
void citire()
{
	freopen("trapez.in","r",stdin);
	freopen("trapez.out","w",stdout);
	scanf("%hd",&n);
	for (short int i=1; i<=n; ++i)
		scanf("%lld%lld",&v[i].x,&v[i].y);
}
void gasesc()
{
	for (int i=1; i<=n; ++i)
		for (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;
	int i=1;
	for ( i=1;i<n; ++i)
		if (p[i]==p[i+1])
			++num;
		else
		{
			dr+=num*(num-1)/2;
			num=1;
		}
	printf("%lld",dr);
}
int main()
{
	citire();
	gasesc();
	return 0;
}