zoukankan      html  css  js  c++  java
  • poj 1474 Video Surveillance (半平面交)

    链接:http://poj.org/problem?id=1474

    Video Surveillance
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 3247   Accepted: 1440

    Description

    A friend of yours has taken the job of security officer at the Star-Buy Company, a famous depart- ment store. One of his tasks is to install a video surveillance system to guarantee the security of the customers (and the security of the merchandise of course) on all of the store's countless floors. As the company has only a limited budget, there will be only one camera on every floor. But these cameras may turn around to look in every direction. 

    The first problem is to choose where to install the camera for every floor. The only requirement is that every part of the room must be visible from there. In the following figure the left floor can be completely surveyed from the position indicated by a dot, while for the right floor, there is no such position, the given position failing to see the lower left part of the floor. 

    Before trying to install the cameras, your friend first wants to know whether there is indeed a suitable position for them. He therefore asks you to write a program that, given a ground plan, de- termines whether there is a position from which the whole floor is visible. All floor ground plans form rectangular polygons, whose edges do not intersect each other and touch each other only at the corners. 

    Input

    The input contains several floor descriptions. Every description starts with the number n of vertices that bound the floor (4 <= n <= 100). The next n lines contain two integers each, the x and y coordinates for the n vertices, given in clockwise order. All vertices will be distinct and at corners of the polygon. Thus the edges alternate between horizontal and vertical. 

    A zero value for n indicates the end of the input.

    Output

    For every test case first output a line with the number of the floor, as shown in the sample output. Then print a line stating "Surveillance is possible." if there exists a position from which the entire floor can be observed, or print "Surveillance is impossible." if there is no such position. 

    Print a blank line after each test case.

    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
    ",cas++);
    80         if(len)
    81             printf("Surveillance is possible.
    
    ");
    82         else printf("Surveillance is impossible.
    
    ");
    83     }
    84     return 0;
    85 }
    View Code
  • 相关阅读:
    洛谷 P5110 块速递推
    洛谷 P3868 [TJOI2009]猜数字
    Codeforces 343D Water Tree
    Codeforces 915E Physical Education Lessons
    洛谷 P2787 语文1(chin1)- 理理思维
    洛谷 P4344 [SHOI2015]脑洞治疗仪
    洛谷 P3338 [ZJOI2014]力
    【模板】珂朵莉树(ODT)(Codeforces 896C Willem, Chtholly and Seniorious)
    【模板】FFT
    Solution of CF911G Mass Change Queries
  • 原文地址:https://www.cnblogs.com/ccccnzb/p/3941029.html
Copyright © 2011-2022 走看看