标签:
Problem DescriptionNo
#include<iostream>
#include<cstdio>
using namespace std;
double a[101],b[101];
int pnpoly(int nvert, double *vertx, double *verty, double testx, double testy)///nvert顶点数,vertx顶点x坐标数组,verty顶点y坐标数组,testx,testy判断坐标
{
int i, j, c = 0;
for (i = 0, j = nvert-1; i < nvert; j = i++)
{
if ( ((verty[i]>testy) != (verty[j]>testy)) &&(testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
c = !c;
}
return c;
}
int main()
{
int n;
double p1,p2;
while (scanf("%d", &n) != EOF)
{
for (int i=0; i<n; ++i) scanf ("%lf%lf", &a[i], &b[i]);
int m;
scanf ("%d", &m);
while (m--)
{
scanf ("%lf%lf", &p1, &p2);
if (pnpoly(n,a,b,p1,p2)) printf ("Yes\n");
else printf ("No\n");
}
}
return 0;
}
HDU 1756 Cupid's Arrow(点在多边形内判定)
标签:
原文地址:http://blog.csdn.net/yangkunpengd/article/details/51352644