Cod sursa(job #3257004)

Utilizator blubecDorobat Tudor blubec Data 16 noiembrie 2024 13:30:52
Problema Regiuni Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <bits/stdc++.h>
#define P 9001
#define Q 29989
using namespace std;

ifstream fin("regiuni.in");
ofstream fout("regiuni.out");
int a[1001], b[1001], c[1001], n;
/// dreapta i are ecuatia a[i]x + b[i]y + c[i] = 0, i=1..n
int m; /// cod[i] = codul punctului i, i=1..m
pair<int,int> cod[1001];

/// ret. semnul lui (a[i],b[i],c[i]) in (x,y)
int F(int i, int x, int y)
{
    if (a[i] * x + b[i] * y + c[i] < 0) return 1;
    return 2;
}

int main()
{
    int x, y, i, j, val1, val2, aux;
    fin >> n >> m;
    for (i = 1; i <= n; i++)
        fin >> a[i] >> b[i] >> c[i];
    for (i = 1; i <= m; i++)
    {
        fin >> x >> y;
        val1 = val2 = 0;
        for (j = 1; j <= n; j++)
        {
            aux = F(j, x, y);
            val1 = (val1 * 10 + aux) % P;
            val2 = (val2 * 10 + aux) % Q;
        }
        cod[i] = {val1,val2};
    }
    sort(cod + 1, cod + m + 1);
    val1 = 1;
    for (i = 2; i <= m; i++)
        if (cod[i].first != cod[i - 1].first || cod[i].second != cod[i-1].second) val1++;
    fout << val1 << "\n";
    /// cod = 5 3 5 1 7 5 1 => 1 1 3 5 5 6 7
    return 0;
}