Pagini recente » Cod sursa (job #274577) | Cod sursa (job #2852475) | Cod sursa (job #2882058) | Cod sursa (job #3196214) | Cod sursa (job #586782)
Cod sursa(job #586782)
#include <cstdio>
FILE *f,*g;
struct cp{int x,y;} c,p;
struct cp2{int x,y,z;} aux,s[800];
cp v[800];
int i,j,n,m;
bool ok;
inline int fu(cp a,cp2 b) {
return (b.x*a.x+b.y*a.y+b.z);
}
int main() {
f=fopen("poligon.in","r");
g=fopen("poligon.out","w");
fscanf(f,"%d%d",&n,&m);
c.x=c.y=0;
for (i=1;i<=n;i++) {
fscanf(f,"%d%d",&v[i].x,&v[i].y);
c.x+=v[i].x;
c.y+=v[i].y;
}
aux.x=v[1].y-v[n].y;
aux.y=v[n].x-v[1].x;
aux.z=v[1].x*v[n].y-v[1].y*v[n].x;
s[1]=aux;
for (i=2;i<=n;i++) {
aux.x=v[i].y-v[i-1].y;
aux.y=v[i-1].x-v[i].x;
aux.z=v[i].x*v[i-1].y-v[i].y*v[i-1].x;
s[i]=aux;
}
c.x=c.x/n;
c.y=c.y/n;
int sol=0;
for (i=1;i<=m;i++) {
fscanf(f,"%d%d",&p.x,&p.y);
ok=true;
for (j=1;j<=n;j++) {
if (fu(p,s[j])*fu(c,s[j])<0) {
ok=false;
break;
}
}
if (ok==true)
sol++;
}
fprintf(g,"%d",sol);
fclose(g);
}