Cod sursa(job #44774)

Utilizator alextheroTandrau Alexandru alexthero Data 31 martie 2007 18:39:42
Problema Regiuni Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <stdio.h>
#include <set>
#include <algorithm>

#define nmax 1005
#define mmax 1005

using namespace std;

int x1[mmax],y1[mmax],grup[mmax],n,m;
double a[nmax],b[nmax],c[nmax];
double px1[nmax],py1[nmax],px2[nmax],py2[nmax];
set <int> s;

double cp(double x1,double y1,double x2,double y2,double x3,double y3) {
	return (double)(x2 - x1) * (y3 - y2) - (x3 - x2) * (y2 - y1);
}

int main() {
	freopen("regiuni.in","r",stdin);
	freopen("regiuni.out","w",stdout);

	scanf("%d%d",&n,&m);
	for(int i = 1; i <= n; i++) {
		scanf("%lf %lf %lf",&a[i],&b[i],&c[i]);
		if(b[i] == 0) b[i] = 0.001;
		px1[i] = 1; px2[i] = 2;
		py1[i] = (double)(- c[i] - (double)a[i] * px1[i]) / b[i];
		py2[i] = (double)(- c[i] - (double)a[i] * px2[i]) / b[i];
	}

	for(int i = 1; i <= m; i++) {
		scanf("%d%d",&x1[i],&y1[i]);
		grup[i] = 1;
	}

	for(int i = 1; i <= n; i++) 
		for(int j = 1; j <= m; j++) {
			double o = cp(px1[i],py1[i],px2[i],py2[i],x1[j],y1[j]);
			grup[j] *= 2;
			if(o > 0) grup[j]++;
		}
	
	for(int i = 1; i <= m; i++) s.insert(grup[i]);
	printf("%d\n",s.size());

	return 0;
}