Cod sursa(job #994355)

Utilizator andreiiiiPopa Andrei andreiiii Data 5 septembrie 2013 12:52:54
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <cstdio>
#include <algorithm>
#define N 1001
#define INF (1<<30)
using namespace std;

struct pc
{
	double x, y;
};
struct segm
{
	pc a, b;
	double p;
	bool operator <(const segm &e) const
	{
		return p<e.p;
	}
};

pc a[N];
segm b[N*N];

int main()
{
	freopen("trapez.in", "r", stdin);
	freopen("trapez.out", "w", stdout);
	int n, m=0, i, j, s=0, sol=0;
	scanf("%d ", &n);
	for(i=1;i<=n;i++)
	{
		scanf("%lf %lf ", &a[i].x, &a[i].y);
		for(j=1;j<i;j++)
		{
			m++;
			b[m].a=a[i];
			b[m].b=a[j];
			if(b[m].a.x==b[m].b.x)
			{
				b[m].p=INF;
			}
			else
			{
				b[m].p=(b[m].a.y-b[m].b.y)/(b[m].a.x-b[m].b.x);
			}
		}
	}
	sort(b+1, b+m+1);
	b[0].p=INF+2;
	for(i=1;i<=m+1;i++)
	{
		if(i==m+1||b[i].p!=b[i-1].p)
		{
			sol+=(s*(s-1)/2);
			s=1;
		}
		else
		{
			s++;
		}
	}
	printf("%d", sol);
}