Cod sursa(job #818707)

Utilizator caliuxSegarceanu Calin caliux Data 17 noiembrie 2012 20:49:35
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#define INF 2.e15
#define eps 1e-14
using namespace std;

class POINT{
private:
	int x, y;
public:
	POINT(){
		x = 0;
		y = 0;
	}
	void set(int x0,int y0){
		x = x0;
		y = y0;
	}
	int getx(){
		return x;
	}
	int gety(){
		return y;
	}
	friend double panta(POINT& other1,POINT& other2){
		if(other1.x == other2.x){
			return INF;
		}
		return ((double)other2.y - other1.y)/(other2.x - other1.x);
	}
};

vector<POINT> vec;
vector<double> v;

bool cmp(double a, double b){
	if( (a-b) <= eps) return 1;
	
	return 0;
}

int main(){
	freopen("trapez.in", "r", stdin);
	freopen("trapez.out", "w", stdout);
	int N, x, y, i, j;
	double c;
	scanf("%d", &N);
	POINT temp;
	for(i = 1; i <= N;i++){
		scanf("%d%d", &x, &y);
		temp.set(x, y);
		vec.push_back(temp);
	}
	for(i = 0; i < N; i++){
		for(j = i + 1; j < N; j++){
			c = panta(vec[i], vec[j]);
			v.push_back(c);
		}
	}
	sort(v.begin(),v.end(),cmp);
	v.push_back(INF);
	int l = 1, max = 0;	
	for(i = 0; i < v.size() - 1;i++){
		if(fabs(v[i + 1 ] - v[i]) < eps){
			l++;	
		}else{
			max += (l * (l - 1) / 2);
			l = 1;
		}
	}
	printf("%d\n",max);
}