zoukankan      html  css  js  c++  java
  • poj 3335 Rotating Scoreboard(半平面交)

    Rotating Scoreboard
    Time Limit: 2000MS   Memory Limit: 65536K
    Total Submissions: 6420   Accepted: 2550

    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, T is the number of test cases. Each test case is specified on a single line of input in the form n x1 y1 x2 y2 ... xn yn where n (3 ≤ n ≤ 100) is the number of vertices in the polygon, and the pair of integers xi yi sequence specify the vertices of the polygon sorted in order.

    Output

    The output contains T lines, 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

    2
    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
    

    Sample Output

    YES
    NO
    /*
    poj 3335 Rotating Scoreboard(半平面交)
    给一个图形,判断是否存在一个位置能够观察到图形内所有的位置
    即一个图形的核
    输入是顺时针,需要倒一下
    
    hhh-2016-05-08 21:18:33
    */
    #include <iostream>
    #include <vector>
    #include <cstring>
    #include <string>
    #include <cstdio>
    #include <queue>
    #include <cmath>
    #include <algorithm>
    #include <functional>
    #include <map>
    using namespace std;
    #define lson  (i<<1)
    #define rson  ((i<<1)|1)
    typedef long long ll;
    using namespace std;
    const int  maxn = 1010;
    const double PI = 3.1415926;
    const double eps = 1e-8;
    
    int sgn(double x)
    {
        if(fabs(x) < eps) return 0;
        if(x < 0)
            return -1;
        else
            return 1;
    }
    
    struct Point
    {
        double x,y;
        Point() {}
        Point(double _x,double _y)
        {
            x = _x,y = _y;
        }
        Point operator -(const Point &b)const
        {
            return Point(x-b.x,y-b.y);
        }
        double operator ^(const Point &b)const
        {
            return x*b.y-y*b.x;
        }
        double operator *(const Point &b)const
        {
            return x*b.x + y*b.y;
        }
    };
    
    struct Line
    {
        Point s,t;
        double k;
        Line() {}
        Line(Point _s,Point _t)
        {
            s = _s;
            t = _t;
            k = atan2(t.y-s.y,t.x-s.x);
        }
        Point operator &(const Line &b) const
        {
            Point res = s;
            double ta = ((s-b.s)^(b.s-b.t))/((s-t)^(b.s-b.t));
            res.x += (t.x-s.x)*ta;
            res.y += (t.y-s.y)*ta;
            return res;
        }
    };
    
    bool HPIcmp(Line a,Line b)
    {
        if(fabs(a.k-b.k) > eps) return a.k<b.k;
        return ((a.s-b.s)^(b.t-b.s)) < 0;
    }
    Line li[maxn];
    void HPI(Line line[],int n,Point res[],int &resn)
    {
        int tot =n;
        sort(line,line+n,HPIcmp);
        tot = 1;
        for(int i = 1; i < n; i++)
        {
            if(fabs(line[i].k - line[i-1].k) > eps)
                line[tot++] = line[i];
        }
        int head = 0,tail = 1;
        li[0] = line[0];
        li[1] = line[1];
        resn = 0;
        for(int i = 2; i < tot; i++)
        {
            if(fabs((li[tail].t-li[tail].s)^(li[tail-1].t-li[tail-1].s)) < eps||
                    fabs((li[head].t-li[head].s)^(li[head+1].t-li[head+1].s)) < eps)
                return;
            while(head < tail && (((li[tail] & li[tail-1]) - line[i].s) ^ (line[i].t-line[i].s)) > eps)
                tail--;
            while(head < tail && (((li[head] & li[head+1]) - line[i].s) ^ (line[i].t-line[i].s)) > eps)
                head++;
            li[++tail] = line[i];
        }
        while(head < tail && (((li[tail] & li[tail-1]) - li[head].s) ^ (li[head].t-li[head].s)) > eps)
            tail--;
        while(head < tail && (((li[head] & li[head-1]) - li[tail].s) ^ (li[tail].t-li[tail].t)) > eps)
            head++;
        if(tail <= head+1)
        return;
        for(int i = head;i < tail;i++)
            res[resn++] = li[i]&li[i+1];
        if(head < tail-1)
            res[resn++] = li[head]&li[tail];
    }
    
    
    Point lis[maxn];
    Line line[maxn];
    int main()
    {
        //freopen("in.txt","r",stdin);
        int n,T;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&n);
            for(int i = 0;i < n;i++)
            {
                scanf("%lf%lf",&lis[i].x,&lis[i].y);
            }
            reverse(lis,lis+n);
            int ans;
            for(int i = 0;i < n;i++)
            {
                line[i] = Line(lis[i],lis[(i+1)%n]);
            }
            HPI(line,n,lis,ans);
            if(ans)
                printf("YES
    ");
            else
                printf("NO
    ");
        }
        return 0;
    }
    

      

  • 相关阅读:
    (原)Lazarus 异构平台下多层架构思路、DataSet转换核心代码
    (学)新版动态表单研发,阶段成果3
    (学) 如何将 Oracle 序列 重置 清零 How to reset an Oracle sequence
    (学)XtraReport WebService Print 报错
    (原)三星 i6410 刷机 短信 无法 保存 解决 办法
    (原) Devexpress 汉化包 制作工具、测试程序
    linux下网络配置
    apache自带ab.exe小工具使用小结
    Yii::app()用法小结
    PDO使用小结
  • 原文地址:https://www.cnblogs.com/Przz/p/5510567.html
Copyright © 2011-2022 走看看