凸多边形 HRBUST - 1429 计算几何_凸包_未调完

任选一个点作为起始点,将其他点按与该点连线的极角排序,二分查询点在哪两个射线之间, 并特别判断一下边界即可.

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#define setIO(s) freopen(s".in","r",stdin)
#define maxn 200000
const double eps = 0.000000000001;
using namespace std;
int n,m;
struct Point {
    double x,y;
    Point (double x = 0,double y = 0) : x(x),y(y){}
}point[maxn],ask[maxn];
int exis(double t) { return (fabs(t) <= eps) ? 0 : (t < 0 ? -1 : 1); }
double det(double x1,double y1,double x2,double y2) { return x1*y2-x2*y1; } 
double cross(Point a,Point b,Point c) { return det(b.x-a.x,b.y-a.y,c.x-a.x,c.y-a.y); } 
bool solve(){
    memset(point,0,sizeof(point));
    memset(ask,0,sizeof(ask));
    for(int i = 1;i <= n; ++i) scanf("%lf%lf",&point[i].x,&point[i].y);
    scanf("%d",&m);
    for(int i = 1;i <= m; ++i) scanf("%lf%lf",&ask[i].x,&ask[i].y); 
    for(int i = 1;i <= m; ++i) {
        int l = 2,r = n,ans = 0;
        if(exis(cross(point[1],ask[i],point[2])) != 1 || exis(cross(point[1],ask[i],point[n])) != -1)
            return false;              
        while(l <= r) {
            int mid = (l + r) >> 1;
            if(exis(cross(point[1],point[mid],ask[i])) == -1)
                r = mid - 1;
            else
                ans = mid,l = mid + 1;
        }
        if(!(exis(cross(point[ans-1],point[ans],ask[i])) == -1)) return false;
    }
    return true;
}
 
int main(){
    //setIO("input");
    while(scanf("%d",&n)!=EOF)
    {
        if(solve())
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

  

posted @   EM-LGH  阅读(146)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 内存占用高分析
· .NET Core GC计划阶段(plan_phase)底层原理浅谈
· .NET开发智能桌面机器人:用.NET IoT库编写驱动控制两个屏幕
· 用纯.NET开发并制作一个智能桌面机器人:从.NET IoT入门开始
· 一个超经典 WinForm,WPF 卡死问题的终极反思
阅读排行:
· 支付宝事故这事儿,凭什么又是程序员背锅?有没有可能是这样的...
· 在线客服系统 QPS 突破 240/秒,连接数突破 4000,日请求数接近1000万次,.NET 多
· C# 开发工具Visual Studio 介绍
· 在 Windows 10 上实现免密码 SSH 登录
· C#中如何使用异步编程
点击右上角即可分享
微信分享提示