Cod sursa(job #3257007)

Utilizator Mereuta_RobertMereuta Robert Mereuta_Robert Data 16 noiembrie 2024 13:33:17
Problema Regiuni Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 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;
pair<int, int> cod[1001]; /// cod[i] = codurile punctului i, i=1..m

/// 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, aux, val2;
    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);
    int cnt = 1;
    for (i = 2; i <= m; i++)
        if (!(cod[i].first == cod[i-1].first
            && cod[i].second == cod[i-1].second)) cnt++;
    fout << cnt << "\n";
    return 0;
}