//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 的格式要求是 "插入 [该代码片段的中文名]"

{
    "对抗搜索+Alpha-Beta  (Find the Winning Move)": {
        "prefix": "acm-7.3胜负",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=6,inf=2e9;",
            "int n=4,cnt,ansX,ansY,A[N][N];char op[5],s[N];",
            "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;",
            "}",
            "inline int check(Re op){",
            "\tfor(Re i=1;i<=n;++i){",
            "\t\tRe cnt1=0,cnt2=0;",
            "\t\tfor(Re j=1;j<=n;++j)cnt1+=(A[i][j]==op),cnt2+=(A[j][i]==op);",
            "\t\tif(cnt1==4||cnt2==4)return 1;",
            "\t}",
            "\tRe cnt1=0,cnt2=0;",
            "\tfor(Re i=1;i<=n;++i)cnt1+=(A[i][i]==op),cnt2+=(A[i][n-i+1]==op);",
            "\tif(cnt1==4||cnt2==4)return 1;",
            "\treturn 0;",
            "}",
            "inline int findmin(Re alpha,Re op);",
            "inline int findmax(Re beta,Re op);//[op=1:�ҵĻغ�]",
            "inline int findmin(Re alpha,Re op){",
            "\tif(cnt==16)return 0;",
            "\tif(check(op^1))return inf;",
            "\tRe ans=inf;",
            "\tfor(Re i=1;i<=n;++i)",
            "\t\tfor(Re j=1;j<=n;++j)",
            "\t\t\tif(A[i][j]==-1){",
            "\t\t\t\tA[i][j]=op,++cnt;",
            "\t\t\t\tans=min(ans,findmax(ans,op^1));",
            "\t\t\t\tA[i][j]=-1,--cnt;",
            "\t\t\t\tif(ans<=alpha)return ans;",
            "\t\t\t}",
            "\treturn ans;",
            "}",
            "inline int findmax(Re beta,Re op){",
            "\tif(cnt==16)return 0;",
            "\tif(check(op^1))return -inf;",
            "\tRe ans=-inf;",
            "\tfor(Re i=1;i<=n;++i)",
            "\t\tfor(Re j=1;j<=n;++j)",
            "\t\t\tif(A[i][j]==-1){",
            "\t\t\t\tA[i][j]=op,++cnt;",
            "\t\t\t\tans=max(ans,findmin(ans,op^1));",
            "\t\t\t\tA[i][j]=-1,--cnt;",
            "\t\t\t\tansX=i,ansY=j;",
            "\t\t\t\tif(ans>=beta)return ans;",
            "\t\t\t}",
            "\treturn ans;",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\twhile(~scanf(\"%s\",op)&&op[0]!='$'){",
            "\t\tcnt=0;",
            "\t\tfor(Re i=1;i<=n;++i){",
            "\t\t\tscanf(\"%s\",s+1);",
            "\t\t\tfor(Re j=1;j<=n;++j)",
            "\t\t\t\tif(s[j]=='.')A[i][j]=-1,++cnt;",
            "\t\t\t\telse A[i][j]=(s[j]=='x');",
            "\t\t}",
            "\t\tif(cnt<=4)puts(\"#####\");",
            "\t\telse if(findmax(inf,1)==inf)printf(\"(%d,%d)\\n\",ansX-1,ansY-1);",
            "\t\telse puts(\"#####\");",
            "\t}",
            "}",
            ""
        ],
        "description": "插入 对抗搜索+Alpha-Beta  (Find the Winning Move)"
    }
}