标签:des style blog http color os io strong for
链接:http://poj.org/problem?id=1474
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 3247 | Accepted: 1440 |
Description
Input
Output
Sample Input
4 0 0 0 1 1 1 1 0 8 0 0 0 2 1 2 1 1 2 1 2 2 3 2 3 0 0
Sample Output
Floor #1 Surveillance is possible. Floor #2 Surveillance is impossible.
Source
1 #include <stdio.h> 2 #include <math.h> 3 #include <string.h> 4 #include <stdlib.h> 5 #include <iostream> 6 #include <algorithm> 7 8 #define eps 1e-8 9 #define MAXX 105 10 using namespace std; 11 typedef struct point 12 { 13 double x; 14 double y; 15 }point; 16 17 point p[MAXX],s[MAXX]; 18 19 bool dy(double x,double y){ return x>y+eps; } 20 bool xy(double x,double y){ return x<y-eps; } 21 bool dyd(double x,double y){ return x>y-eps; } 22 bool xyd(double x,double y){ return x<y+eps; } 23 bool dd(double x,double y){ return fabs(x-y)<eps; } 24 25 double crossProduct(point a,point b,point c) 26 { 27 return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x); 28 } 29 point IntersectPoint(point u1,point u2,point v1,point v2) 30 { 31 point ans=u1; 32 double t=((u1.x-v1.x)*(v1.y-v2.y)-(u1.y-v1.y)*(v1.x-v2.x))/ 33 ((u1.x-u2.x)*(v1.y-v2.y)-(u1.y-u2.y)*(v1.x-v2.x)); 34 ans.x+=(u2.x - u1.x)*t; 35 ans.y+=(u2.y - u1.y)*t; 36 return ans; 37 } 38 39 void cut(point p[],point s[],int n,int &len) 40 { 41 point tp[MAXX]; 42 p[n]=p[0]; 43 for(int i=0; i<=n; i++) 44 { 45 tp[i] = p[i]; 46 } 47 int cp=n,tc; 48 for(int i=0; i<n; i++) 49 { 50 tc=0; 51 for(int k=0; k<cp; k++) 52 { 53 if(dyd(crossProduct(p[i],p[i+1],tp[k]),0.0))//clock-wise 54 s[tc++]=tp[k]; 55 if(xy(crossProduct(p[i],p[i+1],tp[k])* 56 crossProduct(p[i],p[i+1],tp[k+1]),0.0)) 57 s[tc++]=IntersectPoint(p[i],p[i+1],tp[k],tp[k+1]); 58 } 59 s[tc]=s[0]; 60 for(int k=0; k<=tc; k++) 61 tp[k]=s[k]; 62 cp=tc; 63 } 64 len=cp; 65 } 66 67 int main() 68 { 69 int n,i,j; 70 int cas=1; 71 while(scanf("%d",&n)!=EOF && n) 72 { 73 for(i=0 ;i<n; i++) 74 { 75 scanf("%lf%lf",&p[i].x,&p[i].y); 76 } 77 int len; 78 cut(p,s,n,len); 79 printf("Floor #%d\n",cas++); 80 if(len) 81 printf("Surveillance is possible.\n\n"); 82 else printf("Surveillance is impossible.\n\n"); 83 } 84 return 0; 85 }
poj 1474 Video Surveillance (半平面交)
标签:des style blog http color os io strong for
原文地址:http://www.cnblogs.com/ccccnzb/p/3941029.html