Cod sursa(job #785621)

Utilizator danalex97Dan H Alexandru danalex97 Data 9 septembrie 2012 14:22:19
Problema Regiuni Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.57 kb
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int Hsize = 61789;
const int Hsexion = 7;
const int Nmax = 1010 ;

int a[Nmax],b[Nmax],c[Nmax];
int 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=0;
		for (int j=1;j<=N;++j)
			A=( A*Hsexion+( a[j]*x+b[j]*y+c[j] > 0 ) ) % Hsize ;
		
		Hash[i]= A;
	}
	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 );
}
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int Hsize = 31789;
const int Hsexion = 11;
const 

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 ) ) % Hsize ;
		
		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 );
}