Cod sursa(job #2328838)

Utilizator Vladv01Vlad Vladut Vladv01 Data 26 ianuarie 2019 11:04:23
Problema Poligon Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.45 kb
#include <iostream>
#include <fstream>
#include <cmath>


using namespace std;

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


int n,m,xmax,ymax,nrin=0;

struct poligon{

  int x,y;
}p[805];

struct punct{

  int x,y;
}a[60004];


int main()
{
    f>>n>>m;
    for(int i=0;i<n;i++)
    {
        f>>p[i].x;
        if(p[i].x>xmax)
            xmax=p[i].x;
        f>>p[i].y;
        if(p[i].y>ymax)
            ymax=p[i].y;
    }
    for(int i=0;i<m;i++)
    {
        f>>a[i].x;
        f>>a[i].y;
    }

    ymax+=5;
    xmax+=5;
    for(int i=0;i<m;i++)
    {
        int ok=0;
        int x1=a[i].x;
        int y1=a[i].y;
        for(int j=0;j<n;j++)
        {
            int ok1=0,ok2=0;
            int x2=p[j].x;
            int y2=p[j].y;
            int x3=p[j+1].x;
            int y3=p[j+1].y;
             if(j==n-1)
             {
                 x3=p[0].x;
                 y3=p[0].y;
             }
            int det1=(x1-x2)*(ymax-y2)-(y1-y2)*(xmax-x2);
            int det2=(x1-x3)*(ymax-y3)-(y1-y3)*(xmax-x3);
            if(det1*det2<=0)
                ok1=1;
            det1=(x2-x1)*(y3-y1)-(y2-y1)*(x3-x1);
            det2=(x2-xmax)*(y3-ymax)-(y2-ymax)*(x3-xmax);
            if(det1*det2<=0)
                ok2=1;
            if(ok1==1 && ok2==1)
                    ok++;
        }
        if(ok%2==1)
            nrin++;
    }
    g<<nrin+1<<endl;

    return 0;
}