http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2523

思路 :就是先统计一下方阵中1多少2多少,确定一下下一步谁走,然后再从头开始找是0的位置,往上填下一步该谁走的棋,然后判断一下能不能构成三横三竖或者是对角线

#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std ;

int ch[8][3] = {{0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}} ;
int sh[110] ;
int jude(int a,int b,int c)
{
    return sh[a] && (sh[a] == sh[b]) && (sh[a] == sh[c]) ;
}
int main()
{
    int n ;
    cin>>n ;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < 9 ; j++)
            scanf("%d",&sh[j]) ;
        int  xh[3] = {0} ;
        for(int j = 0 ; j < 9 ; j++)
            xh[sh[j]]++ ;
        int next ,flag = 1;
        if(xh[1] == xh[2])
            next = 1 ;
        else next = 2 ;
        for(int j = 0 ; j < 9&&flag ; j++)
        {
            if(sh[j] == 0)
            {
                sh[j] = next ;
                for(int k = 0 ; k < 8&&flag ; k++)
                    if(jude(ch[k][0],ch[k][1],ch[k][2]))
                        flag = 0 ;
                sh[j] = 0 ;
            }
        }
        if(flag)
            cout<<"NO"<<endl ;
        else cout<<"YES"<<endl ;
    }
    return 0 ;
}
View Code

 

posted on 2013-11-26 17:14  枫、  阅读(193)  评论(0编辑  收藏  举报