Cod sursa(job #2566837)

Utilizator victorv88Veltan Victor victorv88 Data 3 martie 2020 13:14:32
Problema Regiuni Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.32 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("regiuni.in");
ofstream g("regiuni.out");

map<string,bool>regiuni;

int ndrepte, npuncte;

struct punct{
    double x, y;
}puncte[1005];

struct dreapta{
    double a, b, c;
    punct pst, pdr;

    void create_pct()
    {
        if (b==0)
        {
            pst.x=pdr.x=(-c)/a;
            pst.y=0;
            pdr.y=10;
        }
        else{
        pst.x=0;
        pst.y=(-c)/b;
        pdr.x=10;
        pdr.y=((-c)-10*a)/b;
        }
    }

}drepte[1005];

double determinant(punct a, punct b, punct c)
{
    return a.x*b.y+b.x*c.y+c.x*a.y-a.y*b.x-b.y*c.x-c.y*a.x;
}

void adaugare_pct(punct p)
{
    string s="";
    for (int i=1; i<=ndrepte; ++i)
    {
        if(drepte[i].a*p.x+drepte[i].b*p.y+drepte[i].c>0)
            s.push_back('1');
        else
            s.push_back('0');
    }
    regiuni[s]=true;
}

int main()
{
    f >> ndrepte >> npuncte;
    for (int i=1; i<=ndrepte; ++i)
    {
        f >> drepte[i].a >> drepte[i].b >> drepte[i].c;
        drepte[i].create_pct();
    }

    for(int i=1; i<=npuncte; ++i)
    {
        f >> puncte[i].x >> puncte[i].y;
        adaugare_pct(puncte[i]);
    }

    int nr=0;
    for (auto it:regiuni)
        nr++;
    g << nr;

    return 0;
}