Cod sursa(job #1835179)

Utilizator flibiaVisanu Cristian flibia Data 26 decembrie 2016 15:12:52
Problema Trapez Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("trapez.in");
ofstream out("trapez.out");

struct asd{
	long double x, y;
};

int n, dim; asd a[1004]; long double k[1000005]; long long ans;
 
int main(){
	in >> n;
	for(int i = 1; i <= n; i++){
		in >> a[i].x >> a[i].y;
	}
	for(int i = 1; i < n; i++)
		for(int j = i + 1; j <= n; j++) 
			if(a[j].x != a[i].x) k[++dim] = (a[j].y-a[i].y)/(a[j].x-a[i].x);
			else k[++dim] = 1e9;
	sort(k + 1, k+ dim + 1);
	int i = 2; int j; 
	while(i <= n)
	{
		j = 1;
		while(k[i] == k[i-1]) j++, i++;
		ans += (j-1)*j/2;
		i++;
	}
	out << ans;
	return 0;
}