hdu_2717_Catch That Cow_bfs】的更多相关文章

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2717 题解:一维简单BFS,详细看代码,0ms. #include<cstdio> #include<queue> using namespace std; ; bool v[maxn]; int n,k; struct nd{ int x,step; }; bool check(int x){ ||x>||v[x])return false; else return true;…
很短的 BFS 队列 HDU_2717_Catch That Cow #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<queue> using namespace std; <<]={}; <<]; int n,k; int main() { cin>>n>>k; queue<…
Catch That Cow 题目大意:FrammerJohn找奶牛,给出n和k.FJ在n处.每次他可以向左移动一格.向右移动一格或者移动到自己当前格子数乘2的地方.求FJ最少移动多少次.其中,FJ和Cow在数轴上. 注释:$1<=n,k<=10^5$. 想法:又是一道bfs裸题.就是通过简单的bfs来找寻最优解.其中,先遍历到的点在后面重新遍历时,所得到的步数一定是更劣的.所以,每个点我们只需要更新一次.我们通过f数组记录f[i]表示从n到i的最小步数.然后,我们可以不另开bool数组,只需…