-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path210109_BOJ_9205.cpp
More file actions
60 lines (47 loc) · 845 Bytes
/
Copy path210109_BOJ_9205.cpp
File metadata and controls
60 lines (47 loc) · 845 Bytes
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
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
int t = 0;
int n = 0;
vector<vector<int>> c;
vector<bool> check;
bool isHappy;
void findAnswer(int r) { // DFS
if (isHappy)
return;
check[r] = true;
if (r == n + 1) {
isHappy = true;
return;
}
for (int i = 0; i < n + 2; ++i) {
if (check[i]) continue;
if (abs(c[r][0] - c[i][0]) + abs(c[r][1] - c[i][1]) <= 1000) {
findAnswer(i);
}
}
}
void input() {
cin >> t;
while (t--) {
cin >> n;
c.assign(n + 2, vector<int>(2, 0));
for (int i = 0; i < n + 2; ++i) {
cin >> c[i][0] >> c[i][1];
}
check.assign(n + 2, false);
isHappy = false;
findAnswer(0);
if (isHappy)
cout << "happy\n";
else
cout << "sad\n";
}
}
int main() {
// ios::sync_with_stdio(false);
// cin.tie(NULL);
input();
return 0;
}