The Game——poj1970

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_44056753/article/details/99701661

细心细心细心 认真读题

这道题目其实很水,但是我还是要把它记录下来,因为这道题让我认识到了认真读题的重要性
因为没有认真读题,前前后后wa了13次,真的醉了,其实把题目的要求看清楚很容易ac

直接暴搜就可以

#include<iostream>
#include<cstring>
using namespace std;
int flag;
int dic[4][2]= {{-1,1},{1,0},{1,1},{0,1}};
int ans_x,ans_y;
int num[21][21];
void dfs()
{
    int aa=0;
    for(int x=1; x<=19&&!flag; x++)
    {
        for(int y=1; y<=19&&!flag; y++)
        {
            if(num[x][y]==0)
                continue;
            for(int i=0; i<4; i++)
            {
                int j=0;
                int dx=x;
                int dy=y;
                while(1)
                {
                    dx=dx+dic[i][0];
                    dy=dy+dic[i][1];
                    if(num[x][y]!=num[dx][dy]||dx<=0||dx>19||dy<=0||dy>19)
                        break;
                    j++;
                }
                if(j==4&&num[x-dic[i][0]][y-dic[i][1]]!=num[x][y])
                {
                    if(num[x][y]==1)
                        flag=1;
                    if(num[x][y]==2)
                        flag=2;
                    ans_x=x;
                    ans_y=y;
                    break;
                }
            }
        }
    }
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        memset(num,0,sizeof(num));
        for(int i=1; i<=19; i++)
            for(int j=1; j<=19; j++)
                cin>>num[i][j];
        flag=0;
        dfs();
        if(flag==0)
            cout<<"0\n";
        if(flag==1)
        {
            cout<<flag<<endl;;
            cout<<ans_x<<" "<<ans_y<<endl;
        }
        if(flag==2)
        {
            cout<<flag<<endl;
            cout<<ans_x<<" "<<ans_y<<endl;
        }
    }
}

仅以此题,献给我的13次wa

猜你喜欢

转载自blog.csdn.net/weixin_44056753/article/details/99701661
今日推荐