• uva10256(计算几何)


    省选前练模板系列;

    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int maxn=533;
    const double eps=1e-10,inf=1e9;
    int n1,n2,m1,m2,pp;
    double mi;
    int dcmp(double x){if(fabs(x)<eps)return 0;return x<0?-1:1;}
    struct vec{
        double x,y,ang;
        vec(){};
        vec(double a,double b){x=a,y=b;}
        vec operator-(vec a){return vec(x-a.x,y-a.y);}
        vec operator+(vec a){return vec(x+a.x,y+a.y);}
        bool operator<(const vec&a)const{
            return dcmp(x-a.x)<0||(dcmp(x-a.x)==0&&y<a.y);
        }
    }p1[maxn],p2[maxn],ch1[maxn],ch2[maxn],p0,t1,t2,t3;
    double cross(vec a,vec b){return a.x*b.y-b.x*a.y;}
    double dot(vec a,vec b){return a.x*b.x+a.y*b.y;}
    bool onli(vec p,vec a1,vec a2){
        if(p.x=a1.x&&p.y==a1.y)return 1;
        if(p.x=a2.x&&p.y==a2.y)return 1;
        return dcmp(cross(a1-p,a2-p))==0&&dcmp(dot(a1-p,a2-p))<0;
    }
    bool jiao(vec a1,vec a2,vec b1,vec b2){
        if(!(min(a1.x,a2.x)<=max(b1.x,b2.x)&&min(b1.y,b2.y)<=max(a1.y,a2.y)&&min(b1.x,b2.x)<=max(a1.x,a2.x)&&min(a1.y,a2.y)<=max(b1.y,b2.y)))
        return 0;
        double c1=cross(a2-a1,b1-a1),c2=cross(a2-a1,b2-a1);
        double c3=cross(b2-b1,a1-b1),c4=cross(b2-b1,a2-b1);
        return dcmp(c1)*dcmp(c2)<=0&&dcmp(c3)*dcmp(c4)<=0;
    }
    bool inbao(vec p,vec* a,int n){
        if(dcmp(cross(a[1]-a[0],p-a[0]))<0||dcmp(cross(a[n-1]-a[0],p-a[0]))>0)return 0;
        if(dcmp(cross(a[1]-a[0],p-a[0]))==0){
            if(onli(p,a[0],a[1]))return 1;
            else return 0;
        }
        if(dcmp(cross(a[n-1]-a[0],p-a[0]))==0){
            if(onli(p,a[0],a[n-1]))return 1;
            else return 0;
        }
        int l=2,r=n-1;
        while(l<r){
            int mid=l+r>>1;
            if(dcmp(cross(p-a[0],a[mid]-a[0]))>0)r=mid;
            else l=mid+1;
        }
        //cout<<l<<endl;
        if(cross(a[l]-a[l-1],p-a[l-1])>=0)return 1;
        return 0;
    }
    int build(vec *p,int n,vec *ch){
        sort(p,p+n);
        int m=0;
        for(int i=0;i<n;++i){
            while(m>1&&cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--;
            ch[m++]=p[i];
        }
        int k=m;
        for(int i=n-2;i>=0;--i){
            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;
    }
    void solve(){
        for(int i=0;i<n1;++i)scanf("%lf%lf",&p1[i].x,&p1[i].y);
        for(int i=0;i<n2;++i)scanf("%lf%lf",&p2[i].x,&p2[i].y);
        if(n1==1&&n2==1){
            if(p1[0].x==p2[0].x&&p1[0].y==p2[0].y){puts("No");return;}
            else{puts("Yes");return;}
        }
        m1=build(p1,n1,ch1),m2=build(p2,n2,ch2);
        if(m2>2){
            for(int i=0;i<m1;++i)if(inbao(ch1[i],ch2,m2)){puts("No");return;}
        }
        if(m1>2){
            for(int i=0;i<m2;++i)if(inbao(ch2[i],ch1,m1)){puts("No");return;}
        }
        for(int i=0;i<m1;++i)
            for(int j=0;j<m2;++j)
            if(jiao(ch1[i],ch1[(i+1)%m1],ch2[j],ch2[(j+1)%m2])){
                  puts("No");return;
        }
        puts("Yes");
    }
    int main(){
        while(scanf("%d%d",&n1,&n2)!=EOF&&n1){
            solve();
        }
        return 0;
    }
    /*
    4 3 
    100 600 
    200 400 
    600 500 
    300 700 
    400 100 
    600 200 
    500 300 
    4 3 
    100 600 
    400 100 
    600 200 
    500 300 
    200 400 
    600 500 
    300 700 
    0 0
    */
  • 相关阅读:
    Xcode 单元测试
    Oracle积累
    懒人小技巧, Toad 常用偷懒方法
    改变UITableView选中行高亮的颜色
    苹果企业版帐号申请记录
    RGB颜色设置错误
    IOS 设置文件是否使用ARC
    懒人的小技巧, 批处理修改IP
    Go连接MYSQL
    Go中的函数和闭包
  • 原文地址:https://www.cnblogs.com/dibaotianxing/p/8711677.html
Copyright © 2020-2023  润新知