CodeForces 754B Ilya and tic-tac-toe game

来源:互联网 发布:c语言入门经典txt下载 编辑:程序博客网 时间:2024/05/27 03:29

题目链接: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
原创粉丝点击