Cod sursa(job #302695)

Utilizator FlorianFlorian Marcu Florian Data 9 aprilie 2009 10:25:09
Problema Regiuni Scor 90
Compilator cpp Status done
Runda Problemiada - Editia 1 Marime 0.83 kb
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
#define Mod 666013
#define MAX_N 1024
#define B 26
int a[MAX_N], b[MAX_N], c[MAX_N];
int x[MAX_N], y[MAX_N];
int n,m;
int h[MAX_N];
void read()
{
	freopen("regiuni.in","r",stdin);
	freopen("regiuni.out","w",stdout);
	scanf("%d%d",&n,&m);
	int i;
	for(i=1;i<=n;++i) scanf("%d%d%d",&a[i],&b[i],&c[i]);
	for(i=1;i<=m;++i) scanf("%d%d",&x[i],&y[i]);
}
int main()
{
	int i,j;
	int P , hash, pz;
	read();
	for(i=1;i<=m;++i)
	{
		hash = 0; P = 1;
		for(j=1;j<=n;++j)
		{
			pz = a[j]*x[i] + b[j]*y[i] + c[j];
			if(pz<0) hash = (hash + P*'a') % Mod;
			else hash = (hash + P*'b') % Mod;
			P = (P*B)%Mod;
		}
		h[i] = hash;
	}
	sort(h+1,h+m+1);
	int sol = 0;
	h[0] = -1;
	for(i=1;i<=m;++i)
		if(h[i] != h[i-1]) ++sol;
	printf("%d\n",sol);
}