//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "闵可夫斯基和": {
        "prefix": "acm-8.3战争",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<cmath>",
            "#define LD double",
            "#define LL long long",
            "#define Vector Point",
            "#define Re register int",
            "using namespace std;",
            "const int N=1e5+3,inf=1e8;",
            "const LD eps=1e-8;",
            "inline int dcmp(LD a){return a<-eps?-1:(a>eps?1:0);}",
            "inline void in(Re &x){",
            "    int f=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')f|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=f?-x:x;",
            "}",
            "struct Point{",
            "\tLD x,y;LD k;Point(LD X=0,LD Y=0){x=X,y=Y;}",
            "\tinline void in(){scanf(\"%lf%lf\",&x,&y);}",
            "\tinline void print(Re op=0){printf(\"(%.2lf %.2lf) \",x,y);if(op)puts(\"\");}",
            "};",
            "inline LD Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}",
            "inline LD Cro(Vector a,Vector b){return a.x*b.y-a.y*b.x;}",
            "inline LD Len(Vector a){return sqrt(Dot(a,a));}",
            "inline Vector operator+(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}",
            "inline Vector operator-(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}",
            "inline Vector operator*(Vector a,LD b){return Vector(a.x*b,a.y*b);}",
            "inline bool cmp1(Vector a,Vector b){return a.x==b.x?a.y<b.y:a.x<b.x;};",
            "inline int ConvexHull(Point *P,Re n,Point *cp){",
            "    sort(P+1,P+n+1,cmp1);",
            "    Re t=0;",
            "    for(Re i=1;i<=n;++i){",
            "        while(t>1&&dcmp(Cro(cp[t]-cp[t-1],P[i]-cp[t-1]))<=0)--t;",
            "        cp[++t]=P[i];",
            "    }",
            "    Re St=t;",
            "    for(Re i=n-1;i>=1;--i){",
            "        while(t>St&&dcmp(Cro(cp[t]-cp[t-1],P[i]-cp[t-1]))<=0)--t;",
            "        cp[++t]=P[i];",
            "    }",
            "    return --t;",
            "}",
            "inline int judge(Point a,Point L,Point R){",
            "\treturn dcmp(Cro(L-a,R-a))>0;",
            "}",
            "inline int PIL(Point a,Point b,Point p){",
            "\treturn !dcmp(Cro(p-a,b-a))&&dcmp(Cro(p-a,p-b))<0;",
            "}",
            "inline int PIP(Point *P,Re n,Point a){",
            "\tif(judge(P[1],a,P[2])||judge(P[1],P[n],a))return 0;",
            "\tif(PIL(P[1],P[2],a)||PIL(P[1],P[n],a))return 1;",
            "\tRe l=2,r=n-1;",
            "\twhile(l<r){",
            "\t\tRe mid=l+r+1>>1;",
            "\t\tif(judge(P[1],P[mid],a))l=mid;",
            "\t\telse r=mid-1;",
            "\t}",
            "\tif(judge(P[l],a,P[l+1]))return 0;",
            "\tif(PIL(P[l],P[l+1],a))return 1;",
            "\treturn 1;",
            "}",
            "Vector V1[N],V2[N];",
            "inline int Mincowski(Point *P1,Re n,Point *P2,Re m,Vector *V){",
            "\tfor(Re i=1;i<=n;++i)V1[i]=P1[i<n?i+1:1]-P1[i];",
            "\tfor(Re i=1;i<=m;++i)V2[i]=P2[i<m?i+1:1]-P2[i];",
            "\tRe t=0,i=1,j=1;V[++t]=P1[1]+P2[1];",
            "\twhile(i<=n&&j<=m)++t,V[t]=V[t-1]+(dcmp(Cro(V1[i],V2[j]))>0?V1[i++]:V2[j++]);",
            "\twhile(i<=n)++t,V[t]=V[t-1]+V1[i++];",
            "\twhile(j<=m)++t,V[t]=V[t-1]+V2[j++];",
            "\treturn t;",
            "}",
            "int n,m,T;Point v,P1[N],P2[N],cp1[N],cp2[N];Vector V[N<<1];",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(m),in(T);",
            "\tfor(Re i=1;i<=n;++i)P1[i].in();",
            "\tfor(Re i=1;i<=m;++i)P2[i].in(),P2[i].x=-P2[i].x,P2[i].y=-P2[i].y;",
            "\tRe cnt1=ConvexHull(P1,n,cp1),cnt2=ConvexHull(P2,m,cp2);",
            "\tRe cnt=Mincowski(cp1,cnt1,cp2,cnt2,V); ",
            "\twhile(T--)v.in(),printf(\"%d\\n\",PIP(V,cnt,v));",
            "}",
            ""
        ],
        "description": "插入 闵可夫斯基和"
    }
}