• sgu Theodore Roosevelt【判断点是否在凸多边形内模板】


    链接:



    253. Theodore Roosevelt

    time limit per test: 0.5 sec.
    memory limit per test: 65536 KB
    input: standard
    output: standard



    Danger! Sudden attack on Russia! These are Americans "again", but this time they are serious. Giant aircraft-carrier "Theodore Roosevelt" is entering the Baltic Sea. At one o'clock American aircraft launched from the carrier bombed Petrozavodsk. 
    At three o'clock we detected the location of "Theodore Roosevelt". In a moment Russian fighters Mig-29 took off into the night air to inflict the crushing strike against the carrier. Using top secret military satellite "Raduga-1" we detected the exact region where the carrier was located - the convex polygon. The fighters launched M rockets and ground forces detected the coordinates of their explosions. 
    You are an indispensable engineer of Russian military forces, and you were waken up by the phone call at four o'clock. They command you to arrive to headquarters for the most important task - detect whether "Theodore Roosevelt" was destroyed or not! You are given all information: the coordinates of vertices of the region polygon and the coordinates of the explosions. 
    It was computed that at least K rockets should have hit the detected region to destroy the carrier. Commander ordered you to complete the work till five o'clock, so you must hurry.

    Input
    The first line of input contains three integers N, M and K (3<=N<=10^5, 0<=K<=M<=10^5). The following N lines contain coordinates of polygon vertices in counter-clockwise order. And then last M lines contain coordinates of rockets explosions. Is is guaranteed that all coordinates are integer numbers not exceeding 10^9 by their absolute value.

    Output
    Output "YES" (without quotes) if "Theodore Roosevelt" was destroyed, or "NO" (without quotes) in the other case.

    Sample test(s)

    Input
    
    
    5 4 2 1 -1 1 2 0 4 -1 2 -1 -1 -2 -1 1 -1 0 1 2 3
    Output
    
    
    YES

    Author: Dmitry Filippov (DEF)
    Resource: Petrozavodsk Summer Training Sessions 2004
    Date: August 25, 2004






    /********************************************************
    A	Accepted	2391 KB	15 ms	Visual Studio C++ 2010	1439 B	2013-07-28 09:57:10
    
    题意:
        给你一个 N 个点的凸多边形
        判断 M 个点是否至少有 K 个点在凸多边形内部或边界
    ********************************************************/
    
    #include<stdio.h>
    #include<math.h>
    
    const int maxn = 100000+10;
    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);
        }
    }p[maxn];
    
    const double eps = 1e-10;
    int dcmp(double x)
    {
        if(fabs(x) < 0) return 0;
        else return x < 0 ? -1 : 1;
    }
    
    double Cross(Point A, Point B)
    {
        return A.x*B.y - A.y*B.x;
    }
    
    /** 点Point 是否在有 n 个顶点的凸多边形内【含边界】*/
    bool isPointInConvex(Point *p, int n, Point point)
    {
        bool flag = true;
        p[n] = p[0];
        int now = dcmp(Cross(p[0]-point, p[1]-point));
        for(int i = 1; i < n; i++)
        {
            int next = dcmp(Cross(p[i]-point, p[i+1]-point));
            if(next*now < 0)
            {
                flag = false;
                break;
            }
            now = next;
        }
        return flag;
    }
    
    int main()
    {
        int n,m,k;
        while(scanf("%d%d%d", &n,&m,&k) != EOF)
        {
            for(int i = 0; i < n; i++)
                scanf("%lf%lf", &p[i].x, &p[i].y);
            Point point;
            int sum = 0;
            while(m--)
            {
                scanf("%lf%lf", &point.x, &point.y);
                if(isPointInConvex(p, n, point))
                    sum++;
            }
            if(sum >= k) printf("YES
    ");
            else printf("NO
    ");
        }
        return 0;
    }
    


  • 相关阅读:
    6-4.粗体标签
    [Unity3D] 如何实现点击按钮退出游戏
    [Unity3D] 载入游戏地图时背景图片随机切换 & 数字百分比进度条
    [Unity3D] 鼠标点击图片移动效果
    [3DMAX]如何将骨骼与模型绑定在一起(蒙皮) & 如何实现自动化人物模型蒙皮
    [Unity 3D]用鼠标滚轮实现镜头放大和缩放,并添加距离限制
    [Unity3D] 如何实现围绕旋转
    [Unity3D] 如何实现注视旋转
    Css 图片自适应
    Scss 定义内层class的简单写法
  • 原文地址:https://www.cnblogs.com/freezhan/p/3223874.html
Copyright © 2020-2023  润新知