Cod sursa(job #1026830)

Utilizator vld7Campeanu Vlad vld7 Data 12 noiembrie 2013 01:29:07
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <set>

using namespace std;

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

const int MAX_N = 1005;
const double WHAT = (1 << 31);

int n, rez;
vector <pair <int, int> > Point;
multiset <double> Set;

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

void solve() {
	double panta;
	
	for (int i = 0; i < n - 1; i++)
		for (int j = i + 1; j < n; j++) {
			if (Point[i].first == Point[j].first)
				panta = WHAT;
			else 
				panta = (double)(Point[j].second - Point[i].second) / (double)(Point[j].first - Point[i].first);
			Set.insert (panta);
		}
		
	for (int i = 0; i < n - 1; i++) 
		for (int j = i + 1; j < n; j++) {
			if (Point[i].first == Point[j].first)
				panta = WHAT;
			else
				panta = (double)(Point[j].second - Point[i].second) / (double)(Point[j].first - Point[i].first);
			rez += (Set.count (panta) - 1);
		}
}

int main() {
	read();
	solve();
	
	g << rez / 2 << '\n';
	
	f.close();
	g.close();
	
	return 0;
}