Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 25124ae

Browse files
Merge pull request #603 from numjax/test
유기농 배추
2 parents 4f45101 + 6ee3be1 commit 25124ae

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

‎ykim9233/백준 1012.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//1éÁØ 1012 À ̄±â3ó1èÃß
2+
3+
4+
#include<bits/stdc++.h>
5+
6+
using namespace std;
7+
8+
int m, n,p;
9+
10+
int nx[4] = { 1,-1,0,0 };
11+
int ny[4] = { 0,0,1,-1 };
12+
13+
int arr[101][101];
14+
int visited[101][101];
15+
16+
void dfs(int x, int y) {
17+
int nxtx, nxty;
18+
for (int i = 0; i < 4; i++) {
19+
nxtx = x + nx[i];
20+
nxty = y + ny[i];
21+
22+
if (nxtx < 0 || nxty < 0 || nxtx >= n || nxty >= m) continue;
23+
24+
if (arr[nxtx][nxty] == 1 && visited[nxtx][nxty] != 1){
25+
visited[nxtx][nxty] = 1;
26+
dfs(nxtx, nxty);
27+
}
28+
}
29+
30+
31+
32+
}
33+
34+
int main() {
35+
cin >> m >> n>> p;
36+
int cnt = 0;
37+
38+
39+
40+
for (int i = 0; i < p; i++) {
41+
int a, b;
42+
cin >> a >> b;
43+
arr[a][b]=1;
44+
}
45+
46+
47+
for (int j = 0; j < m; j++) {
48+
for (int i = 0; i < n; i++) {
49+
if (arr[i][j] == 1 && visited[i][j]!=1) {
50+
cnt++;
51+
visited[i][j] = 1;
52+
dfs(i, j);
53+
}
54+
55+
}
56+
}
57+
58+
cout << cnt;
59+
60+
return 0;
61+
}
62+
63+
64+
65+
66+
67+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /