Cod sursa(job #842129)

Utilizator stoicatheoFlirk Navok stoicatheo Data 26 decembrie 2012 11:45:08
Problema Regiuni Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <cstdio>
#define N 1000
#define k1 666019
#define k2 660013

using namespace std;

int a[N],b[N],c[N],hash1[N],hash2[N];

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);
        hash1[i] = 0, hash2[i] = 0;
        for(j = 0; j < n; j++) {
            hash1[i] = (11 * hash1[i] + (a[j]*x + b[j]*y + c[j] > 0)) % k1;
            hash2[i] = (13 * hash2[i] + (a[j]*x + b[j]*y + c[j] > 0)) % k2;
        }
    }
    for(i = 0; i < m; i++) {
        for(j = 0; j < i; j++)
            if(hash1[i] == hash1[j] && hash2[i] == hash2[j])
                break;
        if(i == j)
            groups++;
    }

    fprintf(g,"%d",groups);

    fclose(f);
    fclose(g);

    return 0;
}