Cod sursa(job #1771104)

Utilizator Gigel-FroneGigel Fronel Gigel-Frone Data 5 octombrie 2016 10:57:06
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <cstdio>
#include <algorithm>
#include <vector>
#define abs(x) (x>=0? x : -x)

using namespace std;

int main()
{
	freopen("trapez.in", "r", stdin);
	freopen("trapez.out", "w", stdout);
	
	int n;
	scanf("%d", &n);
	vector <int> x, y;
	for(int i=1; i<=n; i++)
	{
		int X, Y;
		scanf("%d%d", &X, &Y);
		x.push_back(X);
		y.push_back(Y);
	}
	vector <double> v;
	for(int i=1; i<n; i++)
		for(int j=i+1; j<=n; j++)
		{
				if(y[i]-y[j])
				{
					double tan=double(abs(x[i]-x[j]+0.1-0.1)/abs(y[i]-y[j]+0.1-0.1));
					v.push_back(tan);
				}
				else v.push_back(-1);
		}
	sort(v.begin(), v.end());
	
	int k=0, ans=0;
	vector <double> :: iterator it;
	for(it=v.begin()+1; it<=v.end(); it++)
	{
		if(*it != *(it-1))
		{
			ans+=(k*(k-1)/2);
			k=1;
		}
		else k++;
	}
	printf("%d", ans);
}