Cod sursa(job #307998)

Utilizator Bogdan_tmmTirca Bogdan Bogdan_tmm Data 25 aprilie 2009 19:55:00
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#define ll long long
#define ld long double
#define mp make_pair
using namespace std;
ll x,y,nr;
const ld MAX=(ll)2<<36,prec=0.00000000000000001;
int n,i,j;
typedef pair <ll,ll> p;
vector <p> a;
vector <ld> hash;
inline short cmp(ld x,ld y)
{
	return x-y<prec;
}
int main()
{
	freopen("trapez.in","r",stdin);
	freopen("trapez.out","w",stdout);
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld%lld",&x,&y);
		a.push_back(mp(x,y));
	}
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
		{
			ll m=a[i].first-a[j].first;
			ll n=a[i].second-a[j].second;
			if(!m)
				hash.push_back(0);
			else
				if(!n)
					hash.push_back(MAX);
				else
					hash.push_back((ld)n/m);
		}
	sort(hash.begin(),hash.end());
	hash.push_back(prec);
	int q=0,sz=hash.size()-1;
	while(q<sz)
	{
		int init=q;
		while(hash[q]==hash[init]&&q<sz)
			q++;
		nr+=(q-init)*(q-init-1)/2;
	}
	printf("%lld\n",nr);
	return 0;
}