POJ3278 Catch That Cow
来源:互联网 发布:淘宝网雪地靴女靴 编辑:程序博客网 时间:2024/05/05 03:14
/*algorithm : BFS*/#include <iostream>#include <cstring>#include <queue>#include <algorithm>#include <fstream>using namespace std;const int maxn = 100005;int n, k;int vis[maxn], step[maxn];void BFS(){queue<int> q;int head, next;vis[n] = true;step[n] = 0;q.push(n);while (!q.empty()) {head = q.front();q.pop();for (int i = 0; i < 3; ++i) {if (i == 0) next = head - 1;if (i == 1) next = head + 1;if (i == 2) next = head * 2;if (next < 0 || next >= maxn) continue;if (!vis[next]) {vis[next] = true;step[next] = step[head] + 1;q.push(next);}if (next == k) {cout << step[next] << endl;return;}}}}int main(){while (cin >> n >> k) {memset(vis, 0, sizeof(vis));memset(step, 0, sizeof(step));BFS();}return 0;}
0 0
- POJ3278 Catch That Cow
- poj3278 Catch That Cow
- poj3278 - Catch That Cow
- POJ3278 Catch That Cow
- POJ3278--Catch That Cow
- POJ3278 Catch That Cow
- poj3278 Catch That Cow
- poj3278 Catch That Cow
- poj3278--Catch That Cow
- POJ3278 Catch That Cow
- poj3278 Catch That Cow
- POJ3278,Catch That Cow
- poj3278--Catch That Cow
- POJ3278---Catch That Cow
- poj3278 Catch That Cow
- poj3278 catch that cow
- Catch That Cow poj3278
- Catch That Cow--poj3278
- 编程算法 - 最长公共子序列(LCS) 代码(C)
- Blue Jeans(包含两个查找字符串的重要函数)
- grub rescue语法
- Bit Mask uva+贪心
- Windows Mobile 设备注册到Afaria服务器上
- POJ3278 Catch That Cow
- Java Nio实现socket读写文件
- POJ1003-Hangover(水题)
- 黑马程序员:正则表达式
- 格力空调红外编码分析
- spi_1
- uva 10879(数学)
- linux信号定义
- Win7网络和共享中心 依赖服务或组无法启动 解决办法