Catch That Cow(队列)
来源:互联网 发布:2015网络词 编辑:程序博客网 时间:2024/06/05 05:52
题目:
http://acm.hdu.edu.cn/showproblem.php?pid=2717
第一个数用3种方法(+1,-1,*2)到第二个数 最少步骤;
代码
#include<iostream>#include<cstring>#include<queue>using namespace std;struct node{int x;int step;} ;int s,e;int use[100005];int dfs(int x){queue<node>q;node tp,ans;int tx;ans.x=s;ans.step=0;use[x]=0;q.push(ans);while(!q.empty()){tp=q.front();q.pop();tx=tp.x+1;if(tx<0||tx>100000);else{if(use[tx]){use[tx]=0;ans.x=tx;ans.step=tp.step+1;q.push(ans);if(tx==e)return ans.step;}}tx=tp.x-1;if(tx<0||tx>100000);else{if(use[tx]){use[tx]=0;ans.x=tx;ans.step=tp.step+1;q.push(ans);if(tx==e)return ans.step;}}tx=tp.x*2;if(tx<0||tx>100000);else{if(use[tx]){use[tx]=0;ans.x=tx;ans.step=tp.step+1;q.push(ans);if(tx==e)return ans.step;}}}}int main(){while(cin>>s>>e){if(s==e)cout<<'0'<<endl;else{memset(use,1,sizeof(use));cout<<dfs(s)<<endl;}}return 0;}
0 0
- Catch That Cow(队列)
- poj3278 Catch That Cow (BFS算法和队列)
- 【POJ】3278 - Catch That Cow(bfs,队列)
- POJ 3278 Catch That Cow (队列+bfs)
- POJ 3278 Catch That Cow 【bfs+队列】
- 【HDU 2717 Catch That Cow】+ 队列
- POJ 3278 Catch That Cow(BFS+队列)
- POJ3278(Catch That Cow)
- Catch That Cow(BFS)
- Catch That Cow(BFS)
- Catch That Cow (BFS)
- Catch That Cow (BFS)
- Catch That Cow(BFS)
- HDOJ 2717 Catch That Cow (BFS)
- poj 3278 Catch That Cow(bfs)
- poj Catch That Cow (Bfs)
- hdu 2717 Catch That Cow(搜索)
- POJ 3278 Catch That Cow (BFS)
- statfs函数获取大容量磁盘信息速度慢的解决过程
- [2014.3.30]poj3253 Fence Repair 解题报告(C++)
- Python基础教程(第2版)读书笔记
- 网络流 最大流
- Java中接收键盘输入及输出数据的练习
- Catch That Cow(队列)
- stopPropagation, preventDefault 和 return false 的区别
- 无法解析的外部符号 _WinMain@16
- 团队管理--领导力的重要性
- Twitter Storm源代码分析之Topology的执行过程
- UVA 10003 区间DP
- Java开发中的23种设计模式详解
- 对于云计算的理解
- 关于指针