Created
June 19, 2018 04:26
-
-
Save jwon0615/4c6cadba13b21842830d5dae89a520c3 to your computer and use it in GitHub Desktop.
사무라이
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
#include <stdio.h> | |
int G[100][100]; | |
bool chk[100][100]; | |
int n, m, cnt; | |
void dfs(int x, int y){ | |
if(x<0||x>=n||y<0||y>=m) return; | |
if(chk[x][y]==true) return; | |
chk[x][y]=true; | |
if(chk[x+1][y]==false)dfs(x+1,y); | |
if(chk[x][y+1]==false)dfs(x,y+1); | |
if(chk[x-1][y]==false)dfs(x-1,y); | |
if(chk[x][y-1]==false)dfs(x,y-1); | |
} | |
int main(){ | |
scanf("%d %d", &n, &m); //n세로 m가로 | |
for(int i=0; i<n; i++) | |
for(int j=0; j<m; j++){ | |
scanf("%1d",&G[i][j]); | |
} | |
//slice | |
for(int i=0; i<n; i++) | |
for(int j=0; j<n; j++) | |
if(G[i][j]==8){ | |
chk[i][j]=true; | |
for(int k=0; k<n; k++) | |
chk[k][j]=true; | |
for(int k=0; k<m; k++) | |
chk[i][k]=true; | |
} | |
//dfs | |
for(int i=0; i<n; i++){ | |
for(int j=0; j<m; j++) | |
if(chk[i][j]==false){ | |
cnt++; | |
dfs(i,j); | |
} | |
} | |
printf("%d", cnt); | |
} | |
//1 1 | |
//0 | |
//1 1 | |
//8 | |
//8 9 | |
//000000080 | |
//000000000 | |
//080000000 | |
//000008000 | |
//000000000 | |
//000000000 | |
//000000000 | |
//000000000 | |
//30 50 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000080000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000800000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000800000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000080000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000008000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000800000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//20 50 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000080000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000800000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000800000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000080000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
//00000000008000000000000000000000000000000000000000 | |
//00000000000000000000000000000000000000000000000000 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment