[C++]백준 13700번 완전 범죄
[C++]백준 13700번 완전 범죄
📌문제 링크
https://www.acmicpc.net/problem/13700
📌문제 설명
기본적인 bfs 탐색 문제이다. S부터 탐색하여 D에 도달 시 거리를 출력하고 도달 실패 시 BUG FOUND를 출력한다.
📌코드
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
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
bool mp[100001];
int N, S, D, F, B, K;
void input(){
cin >> N >> S >> D >> F >> B >> K;
for(int i = 0; i < K; i++){
int a;
cin >> a;
mp[a] = true;
}
}
void bfs(){
queue<pair<int, int>> q;
q.push({S, 0});
mp[S] = true;
while(!q.empty()){
auto [x, cnt] = q.front();
q.pop();
if(x == D){
cout << cnt;
return;
}
if(x + F <= N && !mp[x + F]){
mp[x + F] = true;
q.push({x + F, cnt + 1});
}
if(x - B >= 1 && !mp[x - B]){
mp[x - B] = true;
q.push({x - B, cnt + 1});
}
}
cout << "BUG FOUND";
}
void solve(){
input();
bfs();
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
This post is licensed under CC BY 4.0 by the author.