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 #676 (Div. 2) A - D個人題解(E題待補)
- Codeforces Round 928 (Div. 4) B. Vlad and Shapes
- Codeforces Round #537 (Div. 2)B. Average Superhero Gang Power (貪心+暴力)
- Codeforces Round #541 (Div. 2)
- Codeforces Round 940 (Div. 2)
- Codeforces Round 934 (Div. 2)
- Codeforces Round 932 (Div. 2)
- Codeforces Round 948 (Div. 2)
- Codeforces Round #639 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round 987 (Div. 2)
- Codeforces Round 976 (Div. 2)
- Codeforces Round 975 (Div. 2)
- Codeforces Round 986 (Div. 2)
- Codeforces Round 973 (Div. 2)
- Codeforces Round 969 (Div. 2)
- Codeforces Round 873 (Div. 2)
- Codeforces Round 967 (Div. 2)
- Codeforces Round 965 (Div. 2)
- Codeforces Round 963 (Div. 2)
- Codeforces Round 979 (Div. 2)
- Codeforces Round 972 (Div. 2)
- Codeforces Round 949 (Div. 2)
- Codeforces Round 955 (Div. 2)
- Codeforces Round 951 (Div. 2)
- Codeforces Round 961 (Div. 2)
- Codeforces Round 958 (Div. 2)
- Codeforces Round 960 (Div. 2)
- Codeforces Round 953 (Div. 2)
- Codeforces Round 982 (Div. 2)
- Codeforces Round 945 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round 947 (Div. 1 + Div. 2)
- Codeforces Round 941 (Div. 2) D