Cod sursa(job #2214857)

Utilizator mihai50000Mihai-Cristian Popescu mihai50000 Data 20 iunie 2018 12:05:51
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

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

const int NMAX = 1e3 + 5;

struct Punct
{
	int x, y;
}v[NMAX];
double panta[NMAX * NMAX];

int ans = 0;
int m;

int main()
{
	int n;
	f >> n;
	for(int i = 1; i <= n; i++)
		f >> v[i].x >> v[i].y;
	for(int i = 1; i < n; i++)
		for(int j = i + 1; j <= n; j++)
			panta[++m] = (double)(v[j].x - v[i].x) / (v[j].y - v[i].y);
	sort(panta + 1, panta + m + 1);
	for(int i = 1; i < m; i++)
	{
		int nr = 1;
		while(i + 1 <= m && panta[i + 1] == panta[i])
			i++, nr++;
		ans += nr * (nr - 1) / 2;
	}
	g << ans;
}