-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path684C1.cpp
More file actions
141 lines (137 loc) · 5.96 KB
/
684C1.cpp
File metadata and controls
141 lines (137 loc) · 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int,int>,pair<int,int>>>v1;
vector<pair<pair<int,int>,pair<int,int>>>v2;
void four(int i){
printf("%d %d %d %d %d %d",v1[i].first.first,v2[i].second.first,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.second,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].second.first,v2[i].second.first,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.first,v2[i].second.first);
}
void three_one(int i){
printf("%d %d %d %d %d %d",v1[i].first.second,v2[i].second.first,v2[i].second.second);
}
void three_two(int i){
printf("%d %d %d %d %d %d",v1[i].first.first,v2[i].second.first,v2[i].second.second);
}
void three_three(int i){
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.second,v2[i].second.second);
}
void three_four(int i){
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.second,v2[i].second.first);
}
void two_one_two(int i)
{
printf("%d %d %d %d %d %d",v1[i].first.second,v2[i].second.first,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].first.first,v2[i].second.first,v2[i].second.second);
}
void two_one_three(int i)
{
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.second,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.second,v2[i].second.second);
}
void two_one_four(int i){
printf("%d %d %d %d %d %d",v1[i].first.second,v2[i].second.first,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].first.first,v2[i].first.second,v2[i].second.first);
}
void two_two_three(int i){
printf("%d %d %d %d %d %d",v1[i].first.first,v2[i].second.first,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.second,v2[i].second.second);
}
void two_two_four(int i){
printf("%d %d %d %d %d %d",v1[i].first.first,v2[i].first.second,v2[i].second.first);
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].second.first,v2[i].second.second);
}
void one_one(int i){
printf("%d %d %d %d %d %d",v1[i].first.second,v2[i].second.first,v2[i].second.first);
four(i);
}
void one_two(int i){
printf("%d %d %d %d %d %d",v1[i].first.first,v2[i].first.second,v2[i].second.first);
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, m;
scanf("%d %d ", &n, &m);
int arr[n][m];
char c;
getchar();
vector<int>cnt;
for (int i = 0; i < n; i++)
{
for(int j =0; j < m; j++){
scanf("%c", &c);
arr[i][j] = c-48;
}
}
long long int x = 0;
int one = 0;
for (int i = 0; i < m -1; i++)
{
for(int j = 0; j < n-1; j++){
one = 0;
if(j==0){
if(arr[j][i]==1)one++;
if(arr[j][i+1]==1)one++;
}
if(arr[j+1][i]==1)one++;
if(arr[j+1][i+1]==1)one++;
cnt.push_back(one);
x += one;
v1.push_back(make_pair(make_pair(j,i),make_pair(j,i+1)));
v2.push_back(make_pair(make_pair(j+1,i),make_pair(j+1,i+1)));
}
}
printf("%lld\n",x);
for (int i = 0; i < cnt.size(); i++)
{
if(cnt[i]==4){
printf("%d %d %d %d %d %d",v1[i].first.first,v2[i].second.first,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.second,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].second.first,v2[i].second.first,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.first,v2[i].second.first);
}
else if(cnt[i]==3){
if(v1[i].first.first==0){
printf("%d %d %d %d %d %d",v1[i].first.second,v2[i].second.first,v2[i].second.second);
}
else if(v1[i].first.second==0){
printf("%d %d %d %d %d %d",v1[i].first.first,v2[i].second.first,v2[i].second.second);
}
else if(v2[i].second.first==0){
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.second,v2[i].second.second);
}
else {
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.second,v2[i].second.first);
}
}
else if(cnt[i]==2){
if(v1[i].first.first==1 && v1[i].first.second ==1){
printf("%d %d %d %d %d %d",v1[i].first.second,v2[i].second.first,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].first.first,v2[i].second.first,v2[i].second.second);
}
else if(v1[i].first.first==1 && v2[i].second.first==1){
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.second,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.second,v2[i].second.second);
}
else if(v1[i].first.first==1 && v2[i].second.second==1){
printf("%d %d %d %d %d %d",v1[i].first.second,v2[i].second.first,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].first.first,v2[i].first.second,v2[i].second.first);
}
else if(v1[i].first.second==1 && v2[i].second.first==1){
printf("%d %d %d %d %d %d",v1[i].first.first,v2[i].second.first,v2[i].second.second);
printf("%d %d %d %d %d %d",v1[i].first.first,v1[i].first.second,v2[i].second.second);
}
}
else if(cnt[i]==1){
if(v1[i].first.first==1){
printf("%d %d %d %d %d %d",v1[i].first.second,v2[i].second.first,v2[i].second.second);
}
}
}
}
}