Cod sursa(job #1077588)

Utilizator vld7Campeanu Vlad vld7 Data 11 ianuarie 2014 14:48:16
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <fstream>
#include <vector>
#include <algorithm>

#define x first
#define y second

using namespace std;

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

const int MAX_N = 1005;

int n, ans;
vector < pair <int, int> > Point;
vector <double> Slopes;

void read() {
	f >> n;
	for (int i = 1; i <= n; i++) {
		int x, y;
		f >> x >> y;
		Point.push_back (make_pair (x, y));
	}
}

void solve() {
	for (int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++) {
			double slope = (double)(Point[j].y - Point[i].y) / (Point[j].x - Point[i].x);
			Slopes.push_back (slope);
		}
		
	sort (Slopes.begin(), Slopes.end());
	int i = 0;
	while (i < Slopes.size()) {
		int j = i;
		while (j < Slopes.size() && Slopes[i] == Slopes[j])
			j++;
		int frecv = j - i;
		ans += frecv * (frecv - 1) / 2;
		i = j;
	}
}

int main() {
	read();
	solve();
	
	g << ans;
	
	return 0;
}