Cod sursa(job #972401)

Utilizator DaNutZ2UuUUBB Bora Dan DaNutZ2UuU Data 11 iulie 2013 16:46:22
Problema Regiuni Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <fstream>
#include <algorithm>
#define N 1000
#define k1 666019
#define k2 660013

using namespace std;

ifstream fin("regiuni.in"); ofstream fout("regiuni.out");

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

/*
struct dr
{
    short int a, b, c;
}
D[1001];

struct pct
{
    short int x, y;
}
P[1001];

short int n, m, G[1001];

void Read()
{
    fin >> n >> m;

    for(int i = 1; i <= n; i++)
        fin >> D[i].a >> D[i].b >> D[i].c;

    for(int i = 1; i <= m; i++)
        fin >> P[i].x >> P[i].y;
}

*/


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


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

    fout << groups;

    fin.close(); fout.close();

    return 0;
}