Cod sursa(job #787193)

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

using namespace std;

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

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

int main() {
	int n,m,i,j,x,y,key1,key2,groups = 0;

	f>>n>>m;
	for(i = 0; i < n; i++)
		f>>a[i]>>b[i]>>c[i];
	for(i = 0; i < m; i++) {
		f>>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++;
		}
	}

	g<<groups;

	return 0;
}