zoukankan      html  css  js  c++  java
  • 凸多边形 HRBUST

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

    Code:

    #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
    "); 
            else 
                printf("NO
    ");
        }
        return 0; 
    } 
    

      

  • 相关阅读:
    Scrapy(爬虫)基本运行机制
    Python面向对象中的“私有化”
    基于Requests和BeautifulSoup实现“自动登录”
    BeautifulSoup模块
    Python爬虫之-Requests
    踩坑之jinja2注释问题(Flask中)
    Struts2 从一个Action跳至另一个Action
    @JSON(serialize=false),过滤不需要的变量
    JS function的参数问题
    nginx反向代理配置及优化
  • 原文地址:https://www.cnblogs.com/guangheli/p/10540014.html
Copyright © 2011-2022 走看看