zoukankan      html  css  js  c++  java
  • [Codeforces166B]Polygons 凸包

    大致题意:

        给你一个凸多边形A,和一个任意多边形B,判断B是否在A的内部

      先对A的点集建凸包,然后枚举B中的点,二分判断是否在A的内部。

      二分时可用叉积判断,详细见代码

      

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<queue>
    #include<set>
    #include<map>
    #include<stack>
    #include<time.h>
    #include<cstdlib>
    #include<cmath>
    #include<list>
    using namespace std;
    #define MAXN 100100
    #define eps 1e-9
    #define For(i,a,b) for(int i=a;i<=b;i++) 
    #define Fore(i,a,b) for(int i=a;i>=b;i--) 
    #define lson l,mid,rt<<1
    #define rson mid+1,r,rt<<1|1
    #define mkp make_pair
    #define pb push_back
    #define cr clear()
    #define sz size()
    #define met(a,b) memset(a,b,sizeof(a))
    #define iossy ios::sync_with_stdio(false)
    #define fre freopen
    #define pi acos(-1.0)
    #define inf 1e6+7
    #define Vector Point
    const int Mod=1e9+7;
    typedef unsigned long long ull;
    typedef long long ll;
    int dcmp(double x){
        if(fabs(x)<=eps) return 0;
        return x<0?-1:1;
    }
    struct Point{
        double x,y;
        Point(double x=0,double y=0):x(x),y(y) {}
        bool operator < (const Point &a)const{
            if(x==a.x) return y<a.y;
            return x<a.x;
        }
        Point operator - (const Point &a)const{
            return Point(x-a.x,y-a.y);
        }
        Point operator + (const Point &a)const{
            return Point(x+a.x,y+a.y);
        }
        Point operator * (const double &a)const{
            return Point(x*a,y*a);
        }
        Point operator / (const double &a)const{
            return Point(x/a,y/a);
        }
        void read(){
            scanf("%lf%lf",&x,&y);
        }
        void out(){
            cout<<"debug: "<<x<<" "<<y<<endl;
        }
        bool operator == (const Point &a)const{
            return dcmp(x-a.x)==0 && dcmp(y-a.y)==0;
        }
    };
    double Dot(Vector a,Vector b) {
        return a.x*b.x+a.y*b.y;
    }
    double dis(Vector a) {
        return sqrt(Dot(a,a));
    }
    double Cross(Point a,Point b){
        return a.x*b.y-a.y*b.x;
    }
    int ConvexHull(Point *p,int n,Point *ch){
        int m=0;
        For(i,0,n-1) {
            while(m>1 && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
            ch[m++]=p[i];
        }
        int k=m;
        Fore(i,n-2,0){
            while(m>k && Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0) m--;
            ch[m++]=p[i];
        }
        if(n>1) m--;
        return m;
    }
    int n1,n2,m;
    Point p1[100005],p2[100005];
    Point ch[100005];
    bool check(Point tp){
        if(Cross(tp-ch[0],ch[1]-ch[0])>=0 || Cross(tp-ch[0],ch[m-1]-ch[0])<=0) return 0;
        int l=0,r=m-1;
        int now=l;
        while(l<=r) {
            int mid=l+r>>1;
            if(Cross(ch[mid]-ch[0],tp-ch[0])>0) l=mid+1,now=mid;
            else r=mid-1;
        }
        return Cross(ch[(now+1)%m]-ch[now],tp-ch[now])>0;
    }
    void solve(){
        cin>>n1;
        For(i,0,n1-1) p1[i].read();
        cin>>n2;
        For(i,0,n2-1) p2[i].read();
        sort(p1,p1+n1);
        m=ConvexHull(p1,n1,ch);
        int mk=1;
        For(i,0,n2-1) {
            if(!mk) break;
            if(!check(p2[i])) mk=0;
        }
        if(mk) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    int main(){
    //    fre("in.txt","r",stdin);
        int t=0;
        solve();
        return 0;
    }
    View Code
  • 相关阅读:
    中国计算机学会推荐国际学术刊物 会议和期刊目录
    Windows运行(Win+R)快速启动所有程序(自定义)
    解决 Page 'http://localhost:63342/v3/js/math/math.map' requested without authorization页面未授权问题
    如何设置计算机IP地址
    VSCode 设置中文语言
    任意文件夹打开CMD命令窗口
    User-Agent
    关于deepin linux15.6-15.9.1系统播放视频卡顿解决办法
    TCP/IP协议
    HTTP协议
  • 原文地址:https://www.cnblogs.com/cjbiantai/p/9318273.html
Copyright © 2011-2022 走看看