Cod sursa(job #1771087)

Utilizator Gigel-FroneGigel Fronel Gigel-Frone Data 5 octombrie 2016 10:40:41
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

double abs(double x)
{
	if(x>=0) return x;
	else return -(x);
}

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=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;
	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);
}