B. Putting Bricks in the Wall

B. Putting Bricks in the Wall

题意
一个人从S走到F,只能选择一直走1或者一直走0,如果能走到,就要选择一个或者两个点,进行封路(把0变1,1变0)
思路
看到这个题,想办法不让他从S走到F,只需要封住S的两个附近的点和F的两个附近的点,让S附近的两个点都为0(或1),让F的附近两个点都为1(或0)。
思路很好想到,就开始写,但是写完以后WA了,找了好一会还是没找到错误,以为是自己的思路错了,就把这一题放下,去写后面的题了,一直到最后才知道,是自己的有一个判断不到位,才造成的错误,因为有好多种情况需要判断,所以写的时候没有进行很好的划分,所以导致这种低级的错误。
代码

#include<iostream>
#include<algorithm>
using namespace std;
const int N=210;
char a[N][N];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i=1 ; i<=n ; i++)
        {
            for(int j=1 ; j<=n  ; j++) cin>>a[i][j];
        }
        char s1=a[1][2];
        char s2=a[2][1];
        char f1=a[n][n-1];
        char f2=a[n-1][n];
        if(s1==s2&&s1==f1&&s1==f2)
        {
            cout<<"2"<<endl;
            if(s1=='0')
            {
                cout << n << " " << n - 1 << endl;
                cout << n - 1 <<" "<<n<<endl;
            }
            else
            {
                cout<<1<<" "<<2<<endl;
                cout<<2<<" "<<1<<endl;
            }
            continue;
        }
        if(s1==s2&&f1==f2&&s1!=f1)
        {
            cout<<"0"<<endl;
            continue;
        }
        else
        {
            if(s1==s2&&f1!=f2)
            {
                if(s1==f1)
                {
                    cout<<"1"<<endl;
                    cout<<n<<" "<<n-1<<endl;
                    continue;
                }
                if(s1==f2)
                {
                    cout<<"1"<<endl;
                    cout<<n-1<<" "<<n<<endl;
                    continue;
                }
            }
            if(f1==f2&&s1!=s2)
            {
                if(s1==f1)
                {
                    cout<<"1"<<endl;
                    cout<<1<<" "<<2<<endl;
                    continue;
                }
                if(s2==f1)
                {
                    cout<<"1"<<endl;
                    cout<<2<<" "<<1<<endl;
                    continue;
                }
            }
            if(f1!=f2&&s1!=s2)
            {
                cout<<"2"<<endl;
                if(s1=='1')
                {
                    cout<<"1"<<" "<<"2"<<endl;
                }
                else
                {
                    cout<<"2"<<" "<<"1"<<endl;
                }
                if(f1=='0')
                {
                    cout<<n<<" "<<n-1<<endl;
                }
                else
                {
                    cout<<n-1<<" "<<n<<endl;
                }
            }

        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值