728x90
반응형
문제는 여기!
#include <bits/stdc++.h>
using namespace std;
int t, n;
struct Point{
int x;
int y;
};
Point house, festival;
Point cvs[101];
bool isvisited[101];
bool solve(){
queue<pair<int, int>> q;
q.push({house.x, house.y});
while(!q.empty()){
int x = q.front().first;
int y = q.front().second;
q.pop();
if(abs(x-festival.x) + abs(y-festival.y) <= 1000) return true;
for(int i=0; i<n; i++){
if(isvisited[i]) continue;
if(abs(x-cvs[i].x) + abs(y-cvs[i].y) <= 1000) {
isvisited[i] = true;
q.push({cvs[i].x, cvs[i].y});
}
}
}
return false;
}
void input() {
cin >> t;
for(int i=0; i<t; i++){
fill(cvs, cvs+101, Point{0, 0});
fill(isvisited, isvisited+101, false);
cin >> n;
cin >> house.x >> house.y;
for(int c=0; c<n; c++){
cin >> cvs[c].x >> cvs[c].y;
}
cin >> festival.x >> festival.y;
if(solve()) cout << "happy\n";
else cout << "sad\n";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
input();
return 0;
}
728x90
반응형
'알고리즘 > BFS & DFS' 카테고리의 다른 글
[백준/BFS&DFS/C++] 1926번 그림 (0) | 2023.03.02 |
---|---|
[백준/BFS&DFS/C++] 1012번 유기농 배추 (0) | 2023.02.28 |
[백준/구현/BFS&DFS/C++] 2573번 빙산 (0) | 2023.02.09 |
[백준/BFS&DFS/C++] 2468번 안전 영역 (0) | 2023.02.04 |
[백준/BFS&DFS/C++] 2644번 촌수계산 * (0) | 2023.02.01 |