Cod sursa(job #785598)

Utilizator danalex97Dan H Alexandru danalex97 Data 9 septembrie 2012 14:03:46
Problema Regiuni Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int Hsize = 31789;
const int Hsize2 = 27891;
const int Hsexion = 17;
const int Hsexion2 = 11;

const int Nmax = 1010 ;

short a[Nmax],b[Nmax],c[Nmax];
pair<short,short> Hash[Nmax];

int N,M,A,B,Sol;

int main()
{
	FILE *f = fopen("regiuni.in", "r");

    fscanf(f, "%d %d", &N, &M);
	for (int i=1;i<=N;++i)
		fscanf(f, "%d %d %d", &a[i], &b[i] ,&c[i]);
	
	for (int i=1;i<=M;++i)
	{
		int x,y;
		fscanf(f, "%d %d", &x, &y);
		
		A=B=0;
		for (int j=1;j<=N;++j)
			A=( A*Hsexion+( int(a[j])*x+int(b[j])*y+int(c[j]) > 0 ) ) % Hsize ,
			B=( B*Hsexion2+( int(a[j])*x+int(b[j])*y+int(c[j]) > 0 ) ) % Hsize2 ;
		
		Hash[i]= make_pair(short(A),short(B));
	}
	sort(Hash+1,Hash+M+1);
	
	for (int i=1;i<=M;++i)
		if ( Hash[i]!=Hash[i-1] ) ++Sol;
	
	fprintf(fopen("regiuni.out", "w"), "%d\n" , Sol );
}