Pagini recente » Cod sursa (job #1925866) | Cod sursa (job #1354537) | Cod sursa (job #2490352) | Cod sursa (job #20474) | Cod sursa (job #2328804)
#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++;
xmax++;
for(int i=0;i<m;i++)
{
int ok=1;
int x1=a[i].x;
int y1=a[i].y;
for(int j=0;j<m-1;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;
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<<endl;
return 0;
}