UVA 361-cops and Robbers (convex bag)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.