Cod sursa(job #440952)

Utilizator DaninetDani Biro Daninet Data 12 aprilie 2010 18:11:19
Problema Trapez Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <cstdio>
#include <vector>
#include <algorithm>
struct point {
	long x,y;
};
struct slope {
	double slope;
};

bool test(slope a, slope b) { return (a.slope<b.slope); }

int main() {
	FILE *f,*g;
	f = fopen("trapez.in","r");
	g = fopen("trapez.out","w");
	int n;
	fscanf(f,"%d\n",&n);
	point a [n+1];
	for(int i=0; i<n; i++) {
		fscanf(f,"%d %d\n",&a[i].x,&a[i].y);
	}
	std::vector<slope> b;
	slope aux;
	for(int i=0; i<n-1; i++) {
		for(int j=i+1; j<n; j++) {
			if (a[j].x-a[i].x==0) aux.slope = 32000;
			else aux.slope = (double)((a[j].y-a[i].y)*1000)/(a[j].x-a[i].x);
			b.push_back(aux);
		}
	}
	sort(b.begin(), b.end(), test);
	int rez = 0;
	for(int i=1; i!=(int)b.size();i++) {
		if (b[i-1].slope==b[i].slope) { 
			rez++; 
			i = i+2;
		}
	}
	fprintf(g,"%d",rez);

	fclose(f);
	fclose(g);
	
}