POJ - 3278 Catch That Cow(BFS)
来源:互联网 发布:visio软件安装包 编辑:程序博客网 时间:2024/05/22 04:32
题目大意:给你两个坐标,你的位置是第一个坐标
现在有两种操作:操作1:前进一个单位
操作二:前进(当前位置 - 0)个单位
问到达第二个坐标的最小操作数
解题思路:纯BFS裸题
#include <cstdio>#include <cstring>#include <queue>using namespace std;const int N = 200010;struct Node { int pos, time; Node() {} Node(int pos, int time): pos(pos), time(time) {}};bool vis[N];int start, End;void solve() { queue<Node> Q; Q.push(Node(start, 0)); memset(vis, 0, sizeof(vis)); vis[start] = true; while (!Q.empty()) { int x = Q.front().pos; int t = Q.front().time; Q.pop(); if (x == End) { printf("%d\n", t); return ; } if (x + 1 <= End && !vis[x + 1]) { vis[x + 1] = true; Q.push(Node(x + 1, t + 1)); } if (x - 1 >= 0 && !vis[x - 1]) { vis[x - 1] = true; Q.push(Node(x - 1, t + 1)); } if (x * 2 < N && !vis[x * 2]) { vis[x * 2] = true; Q.push(Node(x * 2, t + 1)); } }}int main() { while (scanf("%d%d", &start, &End) != EOF) solve(); return 0;}
0 0
- poj 3278 Catch That Cow BFS
- poj 3278 Catch That Cow BFS
- POJ 3278 Catch That Cow BFS
- poj 3278 bfs(Catch That Cow)
- poj 3278 Catch That Cow(bfs)
- POJ 3278 Catch That Cow bfs
- POJ 3278 Catch That Cow 【bfs+队列】
- POJ 3278 Catch That Cow (BFS)
- POJ 3278 Catch That Cow(BFS)
- poj 3278 Catch That Cow bfs
- poj 3278 Catch That Cow (BFS剪枝)
- POJ 3278 Catch That Cow[BFS]
- Poj 3278 Catch That Cow 裸bfs
- POJ 3278 Catch That Cow(图论:BFS)
- POJ 3278 Catch That Cow (BFS)
- POJ 3278 Catch That Cow (BFS)
- poj 3278 Catch That Cow 【BFS】
- POJ--3278:Catch That Cow (BFS)
- spring source codes import to eclipse.
- Layout及SizeClass 大总结
- 对博客的说明
- Android Studio设置界面风格和字体大小
- matlab中的repmat函数
- POJ - 3278 Catch That Cow(BFS)
- Cocos2d-x源码啃食第一谈
- solr配置ik中文分词
- 安卓手机赚钱APP—学生赚完美版,一天至少50块 有图有真相
- php获取客户端的操作系统类型函数
- XMPP message push实现分析
- VC中利用GDI添加图片
- 30天自制操作系统-30days diy os
- Xtrafinder0.25.5在OS X10.11上的运行配置