Skip to content

Commit

Permalink
Add repo, 장애물인식프로그램_409, DFS, cpp 풀이
Browse files Browse the repository at this point in the history
  • Loading branch information
applebuddy committed Oct 25, 2021
1 parent 9f5f22b commit 16c2dce
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions SofteerAlgorithmPS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
073D54A0272725150083CC94 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 073D549F272725150083CC94 /* main.cpp */; };
073D54A7272729140083CC94 /* 장애물인식프로그램_409.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 073D54A6272729140083CC94 /* 장애물인식프로그램_409.cpp */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -25,6 +26,7 @@
/* Begin PBXFileReference section */
073D549C272725150083CC94 /* SofteerAlgorithmPS */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = SofteerAlgorithmPS; sourceTree = BUILT_PRODUCTS_DIR; };
073D549F272725150083CC94 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
073D54A6272729140083CC94 /* 장애물인식프로그램_409.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = "장애물인식프로그램_409.cpp"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -58,6 +60,7 @@
isa = PBXGroup;
children = (
073D549F272725150083CC94 /* main.cpp */,
073D54A6272729140083CC94 /* 장애물인식프로그램_409.cpp */,
);
path = SofteerAlgorithmPS;
sourceTree = "<group>";
Expand Down Expand Up @@ -119,6 +122,7 @@
buildActionMask = 2147483647;
files = (
073D54A0272725150083CC94 /* main.cpp in Sources */,
073D54A7272729140083CC94 /* 장애물인식프로그램_409.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
56 changes: 56 additions & 0 deletions SofteerAlgorithmPS/장애물인식프로그램_409.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// 장애물인식프로그램_409.cpp
// SofteerAlgorithmPS
//
// Created by MinKyeongTae on 2021/10/26.
//

#if 0

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N, ans=0;
vector<vector<int>> G;
vector<vector<bool>> chk;
vector<int> ansList;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
int cnt=0;

void DFS(int x, int y) {
for(int i=0; i<4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if(nx<0 || ny<0 || nx>=N || ny>=N || G[nx][ny]==0) continue;
if(chk[nx][ny]) continue;
chk[nx][ny]=true;
cnt++;
DFS(nx, ny);
}
}

int main() {
cin>>N;
G = vector<vector<int>>(N, vector<int>(N, 0));
chk = vector<vector<bool>>(N, vector<bool>(N, false));

for(int i=0; i<N; i++)
for(int j=0; j<N; j++) scanf("%01d", &G[i][j]);

for(int i=0; i<N; i++)
for(int j=0; j<N; j++) {
if(chk[i][j] || G[i][j]==0) continue;
chk[i][j]=true;
cnt=1;
DFS(i, j);
ansList.push_back(cnt);
}

sort(ansList.begin(), ansList.end());
printf("%d\n", (int)ansList.size());
for(auto &v: ansList) printf("%d\n", v);
}

#endif

0 comments on commit 16c2dce

Please sign in to comment.