#include <stdio.h> #include <stdlib.h> #include <math.h> #define INF 10000 #define eps 1e-8 #define zero(x) (((x)>0?(x):-(x))<eps) struct point { double x,y; }; struct LINE { point a,b; }; double xmult(point p1,point p2,point p0) { return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y); } int pinplg(int n,point q,point* p) { point q2; int i=0,count; while (i<n) for (count=i=0,q2.x=rand()+INF,q2.y=rand()+INF;i<n;i++) if (zero(xmult(q,p[i],p[(i+1)%n]))&&(p[i].x-q.x)*(p[(i+1)%n].x-q.x)<eps&&(p[i].y-q.y)*(p[(i+1)%n].y-q.y)<eps) return 1; else if (zero(xmult(q,q2,p[i]))) break; else if (xmult(q,p[i],q2)*xmult(q,p[(i+1)%n],q2)<-eps&&xmult(p[i],q,p[(i+1)%n])*xmult(p[i],q2,p[(i+1)%n])<-eps) count++; return count&1; } point p[110],q; int main() { int cas; scanf("%d",&cas); int n; while(cas--) { scanf("%d",&n); int i; scanf("%lf%lf",&q.x,&q.y); for(i=0;i<n;++i) scanf("%lf%lf",&p[i].x,&p[i].y); int t; if(pinplg(n,q,p)) printf("yes/n"); else printf("no/n"); } return 0; }
Sample Input
1
5
100 76
55 118
119 114
147 66
123 33
68 56
Sample Output
yes
Input
The first line of input is a integer t(1<=t<=100),the number of test cases.The first line of each test case contains a integer n(1<=n<=100), the number of vertexes of the fencing.The second line contains the position of the tiger followed by n vertexes of the fencing in counter-closewise order.All numbers are integers in interval[0,10000].
Output
Print "yes" if the tiger is in the fencing or at the border,print "no" if not.