传说世上有一支丘比特的箭,凡是被这支箭射到的人,就会深深的爱上射箭的人。
世上无数人都曾经梦想得到这支箭。Lele当然也不例外。不过他想,在得到这支箭前,他总得先学会射箭。
日子一天天地过,Lele的箭术也越来越强,渐渐得,他不再满足于去射那圆形的靶子,他开始设计各种各样多边形的靶子。
不过,这样又出现了新的问题,由于长时间地练习射箭,Lele的视力已经高度近视,他现在甚至无法判断他的箭射到了靶子没有。所以他现在只能求助于聪明的Acmers,你能帮帮他嘛?
Input
本题目包含多组测试,请处理到文件结束。
在每组测试的第一行,包含一个正整数N(2<N<100),表示靶子的顶点数。
接着N行按顺时针方向给出这N个顶点的x和y坐标(0<x,y<1000)。
然后有一个正整数M,表示Lele射的箭的数目。
接下来M行分别给出Lele射的这些箭的X,Y坐标(0<X,Y<1000)。
Output
对于每枝箭,如果Lele射中了靶子,就在一行里面输出"Yes",否则输出"No"。
Sample Input
4
10 10
20 10
20 5
10 5
2
15 8
25 8
Sample Output
Yes
No
代码:
#include<iostream>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<time.h>
#include<math.h>
#define N 105
#define eps 1e-9
#define pi acos(-1.0)
#define P system("pause")
using namespace std;
struct point
{
double x,y;
point(double a,double b){x=a;y=b;}
point (){};
}p[N],A;
int n;
point operator - (point A,point B)
{
return point(A.x-B.x,A.y-B.y);
}
double dot(point A,point B)//点积
{
return A.x*B.x+A.y*B.y;
}
double cross(point A,point B)//叉积
{
return A.x*B.y-A.y*B.x;
}
int dcmp(double x)//判断实数是否大于0,避免浮点误差
{
if(fabs(x)<eps) return 0;
if(x<0) return -1;
return 1;
}
int isonsegment(point a1,point a2)//判断点是否在线段上
{
if((a2.x==A.x&&a2.y==A.y)||(a1.x==A.x&&A.y==a1.y)) return 1;
return dcmp(cross(a1-A,a2-A))==0&&dcmp(dot(a1-A,a2-A))<0;
}
int isonpoly()//判断点是否在多边形内
{
int i,wn=0;
for(i=0;i<n;i++)
{
if(isonsegment(p[i],p[(i+n)%n]))
return 1;
int k=dcmp(cross(p[(i+1)%n]-p[i],A-p[i]));
int d1=dcmp(p[i].y-A.y);
int d2=dcmp(p[(i+1)%n].y-A.y);
if(k>0&&d1<=0&&d2>0) wn++;
if(k<0&&d2<=0&&d1>0) wn--;
}
if(wn!=0) return 1;
return 0;
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int m;
while(scanf("%d",&n)!=EOF)
{
int i;
for(i=0;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
scanf("%d",&m);
while(m--)
{
scanf("%lf%lf",&A.x,&A.y);
if(isonpoly())
printf("Yes\n");
else printf("No\n");
}
}
// P;
return 0;
}