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;
}