코딩/BOJ & 알고스팟
[BOJ 13700] 완전범죄
hoon222y
2017. 8. 24. 15:39
https://www.acmicpc.net/problem/13700
그냥 bfs문제이다 하지만 주의해야 할 점은 next+f <=n , next-b >0 이어야 한다는 점이다
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 <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <stack> #include <deque> #include <queue> #include <stdio.h> #define INF 1e9 typedef unsigned long long ull; using namespace std; int n,s,d,f,b,k,arr[111111]; bool visit[111111]; void solve(){ queue<pair<int,int>> q; q.push({0,s}); visit[s] = true; while(!q.empty()){ int next = q.front().second; int cnt = q.front().first; q.pop(); if(next == d){ cout << cnt <<endl; return; } if(arr[next+f] == 0 && !visit[next+f] && next+f <=n){ visit[next+f] = true; q.push({cnt+1,next+f}); } if(arr[next-b]== 0 && !visit[next-b] && next-b >=1){ visit[next-b] = true; q.push({cnt+1,next-b}); } } cout << "BUG FOUND" <<endl; } int main(){ memset(arr,0,sizeof(arr)); memset(visit,false,sizeof(visit)); cin >> n >> s >> d >> f >> b >> k; for(int i=1;i<=k;i++){ int a; cin >> a; arr[a] = 1; } solve(); return 0; } | cs |