Codeforces Round #676 (Div. 2) B. Putting Bricks in the Wall
#include<iostream>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N = 210;
int a, b, n, t;
char arr[N][N];
int main() {
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%s", &arr[i]);
}
//起點左邊的點
int s1 = arr[0][1] - '0';
//起點下面的點
int s2 = arr[1][0] - '0';
//終點左邊的點
int e1 = arr[n - 1][n - 2] - '0';
//終點上面的點
int e2 = arr[n - 2][n - 1] - '0';
//起點兩個相鄰點相同的情況下
if(s1 == s2) {
//終點兩個相鄰點相同的情況下
if(e1 == e2) {
if(s1 != e1) printf("0\n");
else printf("2\n1 2\n2 1\n");
//終點兩個相鄰點不相同的情況下
} else {
if(s1 == e1) printf("1\n%d %d\n", n, n - 1);
else printf("1\n%d %d\n", n - 1, n);
}
//起點兩個相鄰點不相同的情況下
} else {
//終點兩個相鄰點相同的情況下
if(e1 == e2) {
if(e1 == s1) printf("1\n%d %d\n", 1, 2);
else printf("1\n%d %d\n", 2, 1);
//終點兩個相鄰點不相同的情況下
} else {
if(s1 == e1) printf("2\n%d %d\n%d %d\n", 1, 2, n - 1, n);
else printf("2\n%d %d\n%d %d\n", 2, 1, n - 1, n);
}
}
}
}
這道題經過分析其實很簡單,其根本的思路就是讓起點的兩個鄰點的值,與終點的兩個鄰點的值不同即可(起點的兩間要鄰點要相等與終點也同理)。
這道題只要分情況討論然後輸出相應結果即可,分析思路如下:
根據這個分析寫程式碼就好了,改法不唯一
相關文章
- Codeforces Round #491 (Div. 2) B. Getting an A
- Codeforces Round #242 (Div. 2) B. Megacity
- Codeforces Round #249 (Div. 2) B. Pasha Maximizes
- Codeforces Round #252 (Div. 2) B. Valera and FruitsUI
- Codeforces Round #246 (Div. 2) B. Football Kit
- Codeforces Round #244 (Div. 2) B. Prison Transfer
- Codeforces Round #228 (Div. 2) B. Fox and CrossROS
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes
- Codeforces Round #243 (Div. 2) B. Sereja and Mirroring
- Codeforces Round #196 (Div. 2) B. Routine Problem
- Codeforces Round #251 (Div. 2) B. Devu, the Dumb Guydev
- Codeforces Round #209 (Div. 2) B. Permutation
- Codeforces Round #676 (Div. 2) A - D個人題解(E題待補)
- Codeforces Round #213 (Div. 2) B. The Fibonacci Segment
- Codeforces Round #248 (Div. 2) B. Kuriyama Mirai's StonesAI
- Codeforces Round #216 (Div. 2) B. Valera and Contest
- Codeforces Round #235 (Div. 2) B. Sereja and Contests
- Codeforces Round #233 (Div. 2) B. Red and Blue Balls
- Codeforces Round #192 (Div. 2) B. Road ConstructionStruct
- Codeforces Round #407 (Div. 1) B. Weird journey
- Codeforces Round 928 (Div. 4) B. Vlad and Shapes
- Codeforces Round #639 (Div. 2)
- Codeforces Round #541 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #448 (Div. 2) A
- Codeforces Round #217 (Div. 2)
- Codeforces Round #256 (Div. 2)
- Codeforces Round #259 (Div. 2)
- Codeforces Round #257 (Div. 2)
- Codeforces Round #258 (Div. 2)
- Codeforces Round #171 (Div. 2)
- Codeforces Round #173 (Div. 2)
- Codeforces Round 932 (Div. 2)
- Codeforces Round 934 (Div. 2)