Cod sursa(job #1077580)

Utilizator vld7Campeanu Vlad vld7 Data 11 ianuarie 2014 14:42:19
Problema Trapez Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <fstream>
#include <vector>
#include <unordered_set>
#include <unordered_map>

#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;
unordered_set <double> Set;
unordered_map <double, int> Hash;

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);
			Hash[slope]++;
			Set.insert (slope);
		}
		
	for (unordered_set <double> :: iterator it = Set.begin(); it != Set.end(); ++it) {
		int frecv = Hash[*it];
		ans += frecv * (frecv - 1) / 2;
	}
}

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