Cod sursa(job #40889)

Utilizator dominoMircea Pasoi domino Data 27 martie 2007 20:21:22
Problema Regiuni Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <stdio.h>
#include <string>

using namespace std;

#define MAX_N 1024
#define PRIME1 666013 
#define PRIME2 10000003 
#define FIN "regiuni.in"
#define FOUT "regiuni.out"

int N, M, A[MAX_N], B[MAX_N], C[MAX_N];
pair<int, int> H[MAX_N];

int main(void)
{
    int i, j, x, y, t, h1, h2;

    freopen(FIN, "r", stdin);
    freopen(FOUT, "w", stdout);

    scanf("%d %d", &N, &M);
    for (i = 0; i < N; i++)
        scanf("%d %d %d", A+i, B+i, C+i);

    for (i = 0; i < M; i++)
    {
        scanf("%d %d", &x, &y);
        h1 = h2 = 0;
        for (j = 0; j < N; j++)
        {
            t = (A[j]*x + B[j]*y + C[j]) < 0;
            h1 = ((h1<<1) + t) % PRIME1;
            h2 = ((h2<<1) + t) % PRIME2;
        }
        H[i] = make_pair(h1, h2);
    }

    sort(H, H+M);
    M = unique(H, H+M)-H;

    printf("%d\n", M);

    return 0;
}