原題鏈接:https://codeforces.com/contest/1421/problem/B

測驗樣例
input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
output
1
3 4
2
1 2
2 1
0
題意: 給定一個 n × n n\times n n×n的迷宮,現在 P i n k Pink Pink在起點 ( 1 , 1 ) (1,1) (1,1)處,終點在 ( n , n ) (n,n) (n,n)處, P i n k Pink Pink在開始游戲之前會選擇一個數 0 0 0或 1 1 1,迷宮的每個格子會存在一個 0 0 0或 1 1 1的數字,游戲規則為 P i n k Pink Pink只能走相鄰的且格子數為開始游戲前選擇的數的格子,現在你最多有兩次機會可以改變元素值,問你怎樣才使得 P i n k Pink Pink不能走到終點,
解題思路: 這是一道思維題,不用想得很深,我們只需要知道 P i n k Pink Pink一開始走出起點的限制有兩個格子 ( 1 , 2 ) (1,2) (1,2)和(2,1),走到終點也有兩個格子限制 ( n ? 1 , n ) (n-1,n) (n?1,n)和 ( n , n ? 1 ) (n,n-1) (n,n?1),那么只要使得這起點格子和終點格子起沖突即可,讓這兩組的格子元素值相反即可, 我們利用if判斷即可得出答案,注意所有情況的考慮,
AC代碼
/*
*郵箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何問題請私信我或評論區留言,謝謝支持,
*
*/
#include<bits/stdc++.h> //POJ不支持
#define rep(i,a,n) for (int i=a;i<=n;i++)//i為回圈變數,a為初始值,n為界限值,遞增
#define per(i,a,n) for (int i=a;i>=n;i--)//i為回圈變數, a為初始值,n為界限值,遞減,
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int inf = 0x3f3f3f3f;//無窮大
const int maxn = 205;//最大值,
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割線,以上為自定義代碼模板***************************************//
int t,n;
char graph[maxn][maxn];
int main(){
//freopen("in.txt", "r", stdin);//提交的時候要注釋掉
IOS;
while(cin>>t){
while(t--){
cin>>n;
rep(i,0,n-1){
cin>>graph[i];
}
char a1=graph[1][0],a2=graph[0][1],b1=graph[n-2][n-1],b2=graph[n-1][n-2];
if(a1!=a2){
if(b1!=b2){
cout<<2<<endl;
if(a1==b1){
cout<<"2 1"<<endl;
cout<<n<<" "<<n-1<<endl;
}
else{
cout<<"2 1"<<endl;
cout<<n-1<<" "<<n<<endl;
}
}
else{
if(a1==b1){
cout<<1<<endl;
cout<<"2 1"<<endl;
}
else{
cout<<1<<endl;
cout<<"1 2"<<endl;
}
}
}
else{
if(b1==b2){
if(b1==a1){
cout<<2<<endl;
cout<<"1 2"<<endl;
cout<<"2 1"<<endl;
}
else{
cout<<0<<endl;
}
continue;
}
if(b1==a1){
cout<<1<<endl;
cout<<n-1<<" "<<n<<endl;
}
else{
cout<<1<<endl;
cout<<n<<" "<<n-1<<endl;
}
}
}
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/185302.html
標籤:其他
