The topic is given n cops and m robbers and Q residents, if a resident in a three cops surrounded by a triangle is safe, otherwise, if in a certain three robbers surrounded by the triangle, is not safe, otherwise is neither.
Idea: This can be converted into a convex hull to do. Determine if a resident is inside a convex hull.
: Here is one of the convex hull's methods of finding
intGetconvexhull (point* p,intN, point* ch) {Sort(p, p + N);//for (int i = 0;i < N;++i) //P[i].write (), puts (""); //Puts (""); intm =0; for(inti =0; I < n; i++) {/ * can be collinear * / //while (M > 1 && dcmp (Getcross (Ch[m-1]-ch[m-2], p[i]-ch[m-1]) < 0) m--; while(M >1&& dcmp (Getcross (ch[m-1]-ch[m-2], p[i]-ch[m-1])) <=0) {//Ch[m-1].write (), puts ("*******");m--; } ch[m++] = P[i]; }intk = m; for(inti = n2; I >=0; i--) {/ * can be collinear * / //while (M > K && dcmp (Getcross (Ch[m-1]-ch[m-2], p[i]-ch[m-2]) < 0) m--; / * Not collinear * / while(M > K && dcmp (Getcross (ch[m-1]-ch[m-2], p[i]-ch[m-1])) <=0) {//Ch[m-1].write (), puts ("$$$$$$$$$$");m--; } ch[m++] = P[i]; }if(N >1) m--;//for (int i = 0;i < M;++i) //Ch[i].write (), puts ("^^ ^^ ^^ ^^"); //Puts (""); returnm;}
点在凸多边形内的判断
intOnpolygonal (Point A, point* p,intN) { for(inti =0; I < n; i++)if(A = = P[i])return 0;if(N >=2) { for(inti =0; I < n; i++) {intv = (i +1)% n;if(Onsegment (A, p[i], p[v]))return 0; } }if(N <=2)return 1;intsig = dCMP ((a-p[0]) * (p[1]-p[0])); for(inti =0; I < n; i++) {intv = (i +1)% n;intTsig = DCMP ((a-p[i]) * (P[v]-p[i]);if(Tsig! = sig)return 1;//Outside the convex polygon}return-1;}
UVA 361-cops and Robbers (convex bag)