-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2022-07-07.cpp
More file actions
88 lines (75 loc) · 1.72 KB
/
2022-07-07.cpp
File metadata and controls
88 lines (75 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream>
using namespace std;
namespace 유기농배추
{
int dy[4] = { -1, 0, 1, 0 };
int dx[4] = { 0, 1, 0, -1 };
int m, n, k, y, x, ret, ny, nx, t;
int a[51][51];
bool visited[51][51];
void dfs(int x, int y) {
visited[x][y] = true;
for (int i = 0; i < 4; ++i)
{
ny = y + dy[i];
nx = x + dx[i];
if (ny < 0 || ny >= n || nx < 0 || nx >= m) continue;
if (a[nx][ny] == 1 && !visited[nx][ny]) dfs(nx, ny);
}
return;
}
int main() {
cin >> t;
while (t--) {
fill(&a[0][0], &a[0][0] + 51 * 51, 0);
fill(&visited[0][0], &visited[0][0] + 51 * 51, 0);
ret = 0;
cin >> m >> n >> k;
for (int i = 0; i < k; i++) {
cin >> x >> y;
a[x][y] = 1;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] == 1 && !visited[i][j]) {
dfs(i, j);
ret++;
}
}
}
cout << "result: " << ret << endl;
}
return 0;
}
}
namespace 주몽
{
int main()
{
int n, m;
int* num;
int cnt(0);
cin >> n >> m;
num = new int[n];
for (int i = 0; i < n; ++i)
{
cin >> num[i];
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; ++j)
{
if (num[i] + num[j] == m)
{
++cnt;
}
}
}
cout << cnt << endl;
return 0;
}
}
int main()
{
return 유기농배추::main();
}