-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcowart.cpp
More file actions
111 lines (108 loc) · 2.9 KB
/
cowart.cpp
File metadata and controls
111 lines (108 loc) · 2.9 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
#include <iostream>
using namespace std;
int n, m, maxx=-1, total=0;
bool visited[1000][1000];
char graph[1000][1000];
void photosizeR(int x, int y){
int a[4] = {x, x, x+1, x-1};
int b[4] = {y-1, y+1, y, y};
for(int i=0; i<4; i++){
int nx=a[i];
int ny=b[i];
if(nx>=0 and ny>=0 and nx<n and ny<n and graph[nx][ny]=='R' and !visited[nx][ny]){
// cout << nx << " " << ny << " " << endl;
visited[nx][ny]=true;
photosizeR(nx, ny);
}
}
return;
}
void photosizeB(int x, int y){
int a[4] = {x, x, x+1, x-1};
int b[4] = {y-1, y+1, y, y};
for(int i=0; i<4; i++){
int nx=a[i];
int ny=b[i];
if(nx>=0 and ny>=0 and nx<n and ny<n and graph[nx][ny]=='B' and !visited[nx][ny]){
// cout << nx << " " << ny << " " << endl;
visited[nx][ny]=true;
photosizeB(nx, ny);
}
}
return;
}
void photosizeG(int x, int y){
int a[4] = {x, x, x+1, x-1};
int b[4] = {y-1, y+1, y, y};
for(int i=0; i<4; i++){
int nx=a[i];
int ny=b[i];
if(nx>=0 and ny>=0 and nx<n and ny<n and graph[nx][ny]=='G' and !visited[nx][ny]){
// cout << nx << " " << ny << " " << endl;
visited[nx][ny]=true;
photosizeG(nx, ny);
}
}
return;
}
int main(){
cin >> n;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
cin >> graph[i][j];
}
}
int Rcounter=0, Bcounter=0, Gcounter=0, CRcounter=0, CBcounter=0;
//Red Human
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(graph[i][j]=='R' and !visited[i][j]){
photosizeR(i,j);
Rcounter++;
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(graph[i][j]=='B' and !visited[i][j]){
photosizeB(i,j);
Bcounter++;
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(graph[i][j]=='G' and !visited[i][j]){
photosizeG(i,j);
Gcounter++;
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
visited[i][j]=false;
if(graph[i][j]=='G'){
graph[i][j]='R';
}
}
}
//cow
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(graph[i][j]=='R' and !visited[i][j]){
photosizeR(i,j);
CRcounter++;
}
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(graph[i][j]=='B' and !visited[i][j]){
photosizeB(i,j);
CBcounter++;
}
}
}
cout << Rcounter+Bcounter+Gcounter << " " << CBcounter + CRcounter << endl;
return 0;
}