Cod sursa(job #787196)

Utilizator cosminx2003Cosmin Clapon cosminx2003 Data 12 septembrie 2012 20:38:49
Problema Regiuni Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <cstdio>
#define N 1000
#define k1 2437
#define k2 2137

using namespace std;

int a[N],b[N],c[N];
bool hash1[k1],hash2[k2];

int main() {
	int n,m,i,j,x,y,key1,key2,groups = 0;
	FILE *f = fopen("regiuni.in","r");
	FILE *g = fopen("regiuni.out","w");

	fscanf(f,"%d %d",&n,&m);
	for(i = 0; i < n; i++)
		fscanf(f,"%d %d %d",&a[i],&b[i],&c[i]);
	for(i = 0; i < m; i++) {
		fscanf(f,"%d %d",&x,&y);
		key1 = 0, key2 = 0;
		for(j = 0; j < n; j++) {
			key1 += (((j+1)*((a[j]*x + b[j]*y + c[j] > 0) ? 1 : 0))<<1) % k1;
			key2 += ((3*(j+1)*((a[j]*x + b[j]*y + c[j] > 0) ? 1 : 0))>>1) %k2;
		}
		if(!hash1[key1%k1] && !hash2[key2%k2]) {
			hash1[key1%k1] = hash2[key2%k2] = true;
			groups++;
		}
	}

	fprintf(g,"%d",groups);
	fclose(f);
	fclose(g);
	
	return 0;
}