• 【codeforces 754B】 Ilya and tic-tac-toe game


    time limit per test2 seconds
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn’t finish the last game. It was Ilya’s turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.

    The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).

    Input
    The tic-tac-toe position is given in four lines.

    Each of these lines contains four characters. Each character is ‘.’ (empty cell), ‘x’ (lowercase English letter x), or ‘o’ (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya’s turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.

    Output
    Print single line: “YES” in case Ilya could have won by making single turn, and “NO” otherwise.

    Examples
    input
    xx..
    .oo.
    x…
    oox.
    output
    YES
    input
    x.ox
    ox..
    x.o.
    oo.x
    output
    NO
    input
    x..x
    ..oo
    o…
    x.xo
    output
    YES
    input
    o.x.
    o…
    .x..
    ooxx
    output
    NO
    Note
    In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.

    In the second example it wasn’t possible to win by making single turn.

    In the third example Ilya could have won by placing X in the last row between two existing Xs.

    In the fourth example it wasn’t possible to win by making single turn.

    【题目链接】:http://codeforces.com/contest/754/problem/B

    【题解】

    枚举那个X放在那个空位;
    放了之后;
    枚举哪一个X是连续三个X中间那个;如果找到了符合要求的就输出有解;
    (复杂度很高吧;但是那么小,怎么搞都能过了);

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%I64d",&x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    //const int MAXN = x;
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    
    char s[9];
    int a[10][10];
    
    bool sear_ch()
    {
        rep1(i,1,4)
            rep1(j,1,4)
            if (a[i][j]==1)
                {
                    if (j-1>=1 && j+1<=4)
                        if (a[i][j-1]==a[i][j] && a[i][j]==a[i][j+1])
                            return true;
                    if (i-1>=1 && i+1<=4)
                        if (a[i+1][j]==a[i][j] && a[i][j]==a[i-1][j])
                            return true;
                    if (i-1>=1 && j-1>=1 && i+1<=4 && j+1<=4)
                        if (a[i-1][j-1]==a[i][j] && a[i][j]==a[i+1][j+1])
                            return true;
        if (i-1>=1 && j+1<=4 && i+1<=4 && j-1>=1)
                 if (a[i-1][j+1]==a[i][j] && a[i][j]==a[i+1][j-1])
                 return true;
                }
        return false;
    }
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        rep1(i,1,4)
        {
            scanf("%s",s+1);
            rep1(j,1,4)
                if (s[j]=='x')
                    a[i][j] = 1;
                else
                    if (s[j]=='o')
                        a[i][j] = 0;
                    else
                        a[i][j] = -1;
        }
        rep1(i,1,4)
            rep1(j,1,4)
                if (a[i][j]==-1)
                {
                    a[i][j]=1;
                    if (sear_ch())
                    {
                        puts("YES");
                        return 0;
                    }
                    a[i][j]=-1;
                }
        puts("NO");
        return 0;
    }
  • 相关阅读:
    预处理
    关键字 static extern
    linux /proc/cpuinfo 不同处理器显示信息
    sscanf函数简介
    阿里云API接口调用
    AD常用命令以及概念
    开源工具、平台列表
    ELK安装部署
    MySQL8.0初体验
    MySQL案例09:Last_IO_Error: Got fatal error 1236 from master when reading data from binary log
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626722.html
Copyright © 2020-2023  润新知