Cod sursa(job #440980)

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

bool test(point a, point b) { 
	if (a.x==0 || b.x==0) return true;
	else return (a.y/a.x<b.y/b.x); 
}

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 = -32117;
			else aux.slope = (double)((a[j].y-a[i].y)*1000)/((a[j].x-a[i].x)*1000);
			//b.push_back(aux);
		}
	}*/
	std::sort(a, a+n, test);
	int rez = 0;
	for(int i=1; i!=n;i++) {
		if (test(a[i-1],a[i])) { 
			rez++; 
			i = i+2;
		}
	}
	fprintf(g,"%d",rez);

	fclose(f);
	fclose(g);
	
}