2021-07-09 AcWing 3762. 二进制矩阵
输入样例:
5 2 2 10 11 3 3 011 101 110 4 4 1111 0110 0110 1111 5 5 01011 11001 00010 11011 10000 2 3 011 101
输出样例:
1 1 1 2 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 3 4 1 1 1 2 2 2 1 3 1 4 2 3 3 2 4 1 4 2 3 3 4 3 4 4 4 1 2 2 1 2 2 1 4 1 5 2 5 4 1 4 2 5 1 4 4 4 5 3 4 2 1 3 2 2 2 3 1 2 2 1 2 2
#include<iostream>
#include<cstdio>
using namespace std;
const int N = 110;
char a[N][N];
void PrintL(int m, int n, int k)//k为折线方向
{
if(k == 1){
printf("%d %d %d %d %d %d\n",m,n,m,n+1,m+1,n);
}else if(k == 2){
printf("%d %d %d %d %d %d\n",m,n-1,m,n,m+1,n);
}else if(k == 3){
printf("%d %d %d %d %d %d\n",m-1,n,m,n,m,n-1);
}else{
printf("%d %d %d %d %d %d\n",m-1,n,m,n,m,n+1);
}
}
int main()
{
int cnt;
int t,x,y;
cin >> t;
while(t--){
cnt=0;
cin >> x >> y;
for(int i = 1; i <= x; i++){
cin >> a[i]+1;
for(int j = 1; j <= y; j++){
if(a[i][j] == '1')
cnt += 3;
}
}
cout << cnt << endl;
for(int i = 1; i <= x; i++){
for(int j = 1; j <= y; j++){
if(a[i][j] == '1')
{
if(i < x && j < y){
PrintL(i, j, 1);
PrintL(i, j+1, 2);
PrintL(i+1, j, 4);
}else if(i == x && j == y){
PrintL(i, j, 3);
PrintL(i-1, j, 2);
PrintL(i, j-1, 4);
}else if(i == x){
PrintL(i, j, 4);
PrintL(i-1, j, 1);
PrintL(i, j+1, 3);
}else{
PrintL(i, j, 2);
PrintL(i, j-1, 1);
PrintL(i+1, j, 3);
}
}
}
}
}
return 0;
}
本文来自博客园,作者:泥烟,CSDN同名, 转载请注明原文链接:https://www.cnblogs.com/Knight02/p/15799181.html