• 【BZOJ5317】【JSOI2018】—部落战争(凸包+闵可夫斯基和)


    传送门

    发现向量xx不合法其实就是可以从Ax=BA-x=B
    也就是x=ABx=A-B
    似乎叫闵可夫斯基和?
    建出凸包后看点在不在凸包内就可以了

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    inline int read(){
        char ch=getchar();
        int res=0,f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
        while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=getchar();
        return res*f;
    }
    const int N=100005;
    struct point{
        double x,y;
        point(double _x=0,double _y=0):x(_x),y(_y){}
        friend inline point operator +(const point &a,const point &b){
            return point(a.x+b.x,a.y+b.y);
        }
        friend inline point operator -(const point &a,const point &b){
            return point(a.x-b.x,a.y-b.y);
        }
        friend inline double operator *(const point &a,const point &b){
            return a.x*b.y-a.y*b.x;	
        }
        inline double calc(){
            return x*x+y*y;
        }
    }p1[N],p2[N],q[N],t1[N],t2[N];
    int n,m,k,top;
    inline bool comp(const point &a,const point &b){
        double res=(a-q[1])*(b-q[1]);
        return (res==0)?((a-q[1]).calc()<(b-q[1]).calc()):(res>0);
    }
    int graham(point *p,int cnt)
    {
        for(int i=1;i<=cnt;i++)q[i]=p[i];
        for(int i=2;i<=cnt;i++)if(q[i].x<q[1].x||q[i].x==q[1].x&&q[i].y<q[1].y)swap(q[1],q[i]);
        sort(q+2,q+cnt+1,comp);top=1;
        for(int i=2;i<=cnt;i++)
        {
            while(top>=2&&(q[top]-q[top-1])*(q[i]-q[top-1])<=0)top--;
            q[++top]=q[i];
        }
        for(int i=1;i<=top;i++)p[i]=q[i];p[top+1]=p[1];
        return top;
    }
    point p[N];int tot;
    inline int check(point a){
        if((a-p[1])*(p[2]-p[1])>0||(a-p[1])*(p[tot]-p[1])<0)return 0;
        int l=2,r=tot,res=2;
        while(l<=r){
            int mid=((l+r)>>1);
            if((p[mid]-p[1])*(a-p[1])>=0)res=mid,l=mid+1;
            else r=mid-1;
        }
        return (p[res%tot+1]-p[res])*(a-p[res])>=0;
    }
    int main(){
        n=read(),m=read(),k=read();
        for(int i=1;i<=n;i++)p1[i].x=read(),p1[i].y=read();
        for(int i=1;i<=m;i++)p2[i].x=-read(),p2[i].y=-read();
        n=graham(p1,n),m=graham(p2,m);
        for(int i=1;i<=n;i++)t1[i]=p1[i+1]-p1[i];
        for(int i=1;i<=m;i++)t2[i]=p2[i+1]-p2[i];
        int f1=1,f2=1;p[tot=1]=p1[1]+p2[1];
        while(f1<=n&&f2<=m)p[++tot]=p[tot-1]+((t1[f1]*t2[f2]>=0)?t1[f1++]:t2[f2++]);
        while(f1<=n)p[++tot]=p[tot-1]+t1[f1++];
        while(f2<=m)p[++tot]=p[tot-1]+t2[f2++];
        tot=graham(p,tot);
        while(k--){
            point a;a.x=read(),a.y=read();
            cout<<check(a)<<'
    ' ;
        }
    }
    
  • 相关阅读:
    git 还原某个文件~~~
    uniqid()
    array_filter 过滤一维中空数组,数组的序列不变
    加密 解密
    gitlab基本维护和使用
    vim 单文件中查找方法
    php数组定义
    $('.goods_tag_ids_all')[0].checked = true;//~~~~~ 单条改变checkbox 属性样式
    由买冰箱想到的
    2014年年终总结
  • 原文地址:https://www.cnblogs.com/stargazer-cyk/p/11145619.html
Copyright © 2020-2023  润新知