Cod sursa(job #811267)

Utilizator Vlad.PPetcu Vlad Vlad.P Data 11 noiembrie 2012 19:50:55
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.07 kb
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#define INF 2147483646
#define eps 1e-14
using namespace std;
class POINT{
	private:
		int x,y;
	public:
		POINT(){
			x=y=0;
		}
		void set(int x2,int y2){
			x=x2;
			y=y2;
		}
		int getx(){
			return x;
		}
		int gety(){
			return y;
		}
		friend double panta(POINT &a,POINT &b){
			if(a.x==b.x){
				return INF;
			}
			return ((double)b.y-a.y)/((double)b.x-a.x);
		}
};
vector<POINT> v;
double p[1001000];
bool cmp(double a, double b){
	if(a-b<=eps){
		return 1;
	}
	else{
		return 0;
	}
}
int main(){
	freopen("trapez.in","r",stdin);
	freopen("trapez.out","w",stdout);
	int n,x,y,i,t=0,j,l=1,lmax=0;
	POINT temp;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d%d",&x,&y);
		temp.set(x,y);
		v.push_back(temp);
	}
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			p[++t]=panta(v[i],v[j]);
		}
	}
	sort(p+1,p+t+1,cmp);
	p[++t]=INF;
	for(i=1;i<t;i++){
		if(fabs(p[i+1]-p[i])<eps)
			l++;
		else{
			lmax+=(l*(l-1)/2);
			l=1;
		}
	}
	printf("%d\n",lmax);
	return 0;
}