-
Notifications
You must be signed in to change notification settings - Fork 1
/
09205.cpp
46 lines (41 loc) · 950 Bytes
/
09205.cpp
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
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef struct Coord {
int x, y;
Coord() : x(0), y(0) {}
Coord(int x, int y) : x(x), y(y) {}
int dist(Coord& c) {
return abs(x - c.x) + abs(y - c.y);
}
} Coord;
bool solve(void) {
int n; cin >> n;
Coord a; cin >> a.x >> a.y;
vector<Coord> v(n);
for (int i=0; i<n; i++) cin >> v[i].x >> v[i].y;
Coord b; cin >> b.x >> b.y;
vector<bool> visited(n, false);
queue<Coord> q; q.push(a);
while (!q.empty()) {
Coord cur = q.front(); q.pop();
if (cur.dist(b) <= 1000) return true;
for (int i=0; i<n; i++) {
if (visited[i]) continue;
if (cur.dist(v[i]) <= 1000) {
q.push(v[i]);
visited[i] = true;
}
}
}
return false;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin >> t;
while (t--) cout << (solve() ? "happy" : "sad") << "\n";
return 0;
}