Cod sursa(job #1338665)

Utilizator lauratalaatlaura talaat lauratalaat Data 10 februarie 2015 10:47:52
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<stdio.h>
#include<algorithm>
using namespace std;
struct bine { int x ; int y ;};
bine v[1001],v2[500001];
bool sortare ( bine a , bine b ){
	return a.y*b.x < b.y*a.x;
}
int main(){
	int n,i,j,x1,y1,l,lmax,p,k=0;
	freopen("trapez.in","r",stdin);
	freopen("trapez.out","w",stdout);
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d %d",&v[i].x,&v[i].y);
	for(i=1;i<=n-1;i++)
		for(j=i+1;j<=n;j++){
			x1=v[i].x-v[j].x;
			y1=v[i].y-v[j].y;
			k++;
			v2[k].x=x1;
			v2[k].y=y1;
		}
	sort(v2+1,v2+k+1,sortare);
	l=1; lmax=1;
	for(i=1;i<=k-1;i++)
		if( (v2[i].y*v2[i+1].x )== (v2[i+1].y* v2[i].x))
			l++;
		else{
			if(l>lmax)
				lmax=l;
			l=1;
		}
	if(l>lmax)
		lmax=l;
	printf("%d\n",lmax*(lmax-1)/2);
	return 0;
}