Poj 3335 (semi-plane intersection)

Source: Internet
Author: User

Link: http://poj.org/problem? Id = 3335 // a template question that is frequently said by Daniel

----------------------------------------------------------------

Rotating scoreboard
Time limit:2000 ms   Memory limit:65536 K
Total submissions:5158   Accepted:2061

Description

This year, ACM/ICPC world finals will be held in a hall in form of a simple polygon. the coaches and spectators are seated along the edges of the polygon. we want to place a rotating scoreboard somewhere in the hall such that a spectator sitting anywhere on the boundary of the hall can view the Scoreboard (I. E ., his line of sight is not blocked by a wall ). note that if the line of sight of a spectator is tangent to the polygon boundary (either in a vertex or in an edge), he can still view the scoreboard. you may view spectator's seats as points along the boundary of the simple polygon, and consider the scoreboard as a point as well. your program is given the corners of the hall (the vertices of the polygon), and must check if there is a location for the Scoreboard (a point inside the polygon) such that the scoreboard can be viewed from any point on the edges of the polygon.

Input

The first number in the input line,TIs the number of test cases. Each test case is specified on a single line of input in the formN X1Y1X2Y2...XN YNWhereN(3 ≤N≤ 100) is the number of vertices in the polygon, and the pair of IntegersXI YiSequence specify the vertices of the polygon sorted in order.

Output

The output containsTLines, each corresponding to an input test case in that order. The output line contains either yes or no depending on whether the scoreboard can be placed inside the hall conforming to the problem conditions.

Sample Input

24 0 0 0 1 1 1 1 08 0 0  0 2  1 2  1 1  2 1  2 2  3 2  3 0

Sample output

YESNO

Source

Tehran 2006 Preliminary else saw N for a long time, I feel it is difficult to see here: http://blog.csdn.net/dream_ysl/article/details/7831293 here: http://blog.csdn.net/zxy_snow/article/details/6596237 here: I think that half plane really need to spend a lot of effort, first, we need to understand how N ^ 2 is obtained. // use each side of the given polygon to cut itself. Second, we need to judge whether the given point is clockwise or clockwise, you need to add judgment // use the area of the source to determine the positive and negative three to understand the code, each cut after the number of sides to be updated, for the next cycle 4 to their own painting on the draft paper, I must understand it before doing the question (test template) else )-----------------------------------------------------------------------------------
 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <iostream> 5 #include <algorithm> 6 #include <math.h> 7  8 using namespace std; 9 10 #define eps 1e-811 #define MAXX 10512 typedef struct13 {14     double x;15     double y;16 }point;17 18 point p[MAXX],s[MAXX];19 20 bool dy(double x,double y) {return x>y+eps; }21 bool xy(double x,double y) {return x<y-eps; }22 bool dyd(double x,double y){return x>y-eps; }23 bool xyd(double x,double y){return x<y+eps; }24 bool dd(double x,double y) {return fabs(x-y)<eps; }25 26 double crossProduct(point a,point b,point c)27 {28     return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);29 }30 31 point IntersectPoint(point u1,point u2,point v1,point v2)32 {33     point ans=u1;34     double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))/35              ((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x));36     ans.x += (u2.x-u1.x)*t;37     ans.y += (u2.y-u1.y)*t;38     return ans;39 }40 41 void cut(point p[],point s[],int n,int &len)42 {43     point tp[MAXX];44     p[n]=p[0];45     for(int i=0; i<=n; i++)46     {47         tp[i]=p[i];48     }49     int cp=n,tc;50     for(int i=0; i<n; i++)51     {52         tc=0;53         for(int k=0; k<cp; k++)54         {55             if(dyd(crossProduct(p[i],p[i+1],tp[k]),0.0))56                 s[tc++]=tp[k];57             if(xy(crossProduct(p[i],p[i+1],tp[k])*58                   crossProduct(p[i],p[i+1],tp[k+1]),0.0))59                 s[tc++]=IntersectPoint(p[i],p[i+1],tp[k],tp[k+1]);60         }61         s[tc]=s[0];62         for(int k=0; k<=tc; k++)63             tp[k]=s[k];64         cp=tc;65     }66     len=cp;67 }68 69 int main()70 {71     int n,m,i,j;72     scanf("%d",&n);73     while(n--)74     {75         scanf("%d",&m);76         for(i=0; i<m; i++)77             scanf("%lf%lf",&p[i].x,&p[i].y);78             int len;79             cut(p,s,m,len);80         if(len)printf("YES\n");81         else printf("NO\n");82     }83     return 0;84 }
View code

 

Poj 3335 (semi-plane intersection)

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.