CodeForces 754B Ilya and tic-tac-toe game

题目链接:http://codeforces.com/contest/754/problem/B
题意:给你一个4x4的棋盘,然后上面有一些棋子,x和o,x是先手的,如果有三个一样的符号连在一起那一方就胜利,问你x能否胜利,能就输出YES,否则输出NO
解析:其实就是那个xo棋,只是棋盘变大了,我一开始以为会复杂,所以懒得想直接判断先手第一步能否胜利,不能就直接输出NO了,因为我两边都赢不了的话,那就只能走平局了,毕竟我玩3x3的时候多半都是平局,代码有点丑。

#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
char a[10][10];
bool judge(char x)
{
    for(int i=0;i<4;i++)
    {
        for(int j=0;j<4;j++)
        {
            if(a[i][j]==x)
            {
                if(a[i+1][j]==x && (a[i+2][j]=='.' || a[i-1][j]=='.'))
                    return true;
                if(a[i][j+1]==x && (a[i][j+2]=='.' || a[i][j-1]=='.'))
                    return true;
                if(a[i+1][j+1]==x && (a[i+2][j+2]=='.' || a[i-1][j-1]=='.'))
                    return true;
                if(a[i+1][j-1]==x && (a[i+2][j-2]=='.' || a[i-1][j+1]=='.'))
                    return true;
                if(a[i+2][j]==x && a[i+1][j]=='.')
                    return true;
                if(a[i][j+2]==x && a[i][j+1]=='.')
                    return true;
                if(a[i+2][j+2]==x && a[i+1][j+1]=='.')
                    return true;
                if(a[i+2][j-2]==x && a[i+1][j-1]=='.')
                    return true;
            }
        }
    }
    return false;
}
int main(void)
{
    for(int i=0;i<4;i++)
        scanf("%s",a[i]);
    if(judge('x'))
        puts("YES");
    else
        puts("NO");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值