-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from AlgoLeadMe/8-dhlee777
8-dhlee777
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include<iostream> | ||
using namespace std; | ||
char color[100][100]; //μ μμΈμ΄ 보λ κ·Έλ¦Ό | ||
char color2[100][100]; //μ λ‘μμ½μ΄ 보λ κ·Έλ¦Ό | ||
bool visited[100][100]; //μ μμΈ κ·Έλ¦Όμ λ°©λ¬Έμ¬λΆ | ||
bool visited2[100][100]; //μ λ‘μμ½ κ·Έλ¦Όμ λ°©λ¬Έμ¬λΆ | ||
string line; // νμ€ μ λ ₯μ λ°κΈ°μν μ€νΈλ§ | ||
int siz; //κ·Έλ¦Όμ ν λ³μ κΈΈμ΄ | ||
int coun = 0; //μ μμΈμ΄ κ·Έλ¦Όμλ΄€μλ ꡬμμκ°μ | ||
int coun2 = 0; //μ λ‘μμ½μ΄ λ΄€μλ ꡬμμκ°μ | ||
int x[4]={0,0,-1,1}; //μνμ’μ° νμμ μν xμ’ν μ΄λκ° | ||
int y[4] = { -1,1,0,0 }; // yμ’ν μ΄λκ° | ||
|
||
void dfs(int a,int b,char color[][100], bool visited[][100]) { //x:νμμμ μ’ν,y:νμμμ yμ’ν color:μ μμΈμ νμμΈμ§ μ λ‘μμ½μ νμμΈμ§ | ||
for (int i = 0; i < 4; i++) { | ||
int a2 = a + x[i]; | ||
int b2 = b + y[i]; | ||
if (a2 >= 0 && a2 < siz && b2 >= 0 && b2 < siz && !visited[a2][b2]&&color[a][b]==color[a2][b2]) { | ||
visited[a2][b2] = true; | ||
dfs(a2, b2,color,visited); | ||
} | ||
} | ||
} | ||
int main(void) { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
cin >> siz; | ||
for (int i = 0; i < siz; i++) { //color,clolor2λ°°μ΄μ κ·Έλ¦Όμ μ λ ₯λ°μ μ μ₯ν΄μ€λ€. | ||
cin >> line; | ||
for (int j = 0; j < siz; j++) { | ||
color[i][j] = line[j]; | ||
if (line[j] == 'R') color2[i][j] = 'G'; //μ λ‘μμ½μ μν΄ rμ gλ‘ λ€ λ°κΏμ μ μ₯ν΄μ€λ€. | ||
else color2[i][j] = line[j]; | ||
} | ||
} | ||
|
||
for (int i = 0; i < siz; i++) { //μ μμΈμ νμ | ||
for (int j = 0; j < siz; j++) { | ||
if (!visited[i][j]) { | ||
dfs(i,j,color,visited); | ||
coun++; | ||
} | ||
} | ||
} | ||
for (int i = 0; i < siz; i++) { //μ λ‘μμ½μ νμ | ||
for (int j = 0; j < siz; j++) { | ||
if (!visited2[i][j]) { | ||
dfs(i, j, color2,visited2); | ||
coun2++; | ||
} | ||
} | ||
} | ||
cout << coun <<" "<< coun2; | ||
return 0; | ||
} |