Skip to content

Instantly share code, notes, and snippets.

@jwon0615 jwon0615/SAmurai.cpp
Created Jun 19, 2018

Embed
What would you like to do?
사무라이
#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
You can’t perform that action at this time.