POJ3278——Catch That Cow
2013-03-21 23:04
344 查看
题目大意:给你两个整数,n和k,n有三种方式移动,n+1,n-1,n*2, 最快让n==k
;
解题方法:宽度搜索,剪枝,三入口搜索
技巧:■ 数组要开的大
■ 注意剪枝,不然 RE
Source Code Problem: 3278 User: Smile_7 Memory: 1324K Time: 32MS Language: C++ Result: Accepted #include <iostream> #include <cstring> using namespace std; const int MAX = 200030; typedef class { public: int x; int step; }point; int n , k ; bool vist[MAX]; point queue[MAX]; void bfs() { int head , tail; queue[head = tail = 0].x = n; queue[tail++].step = 0; vist = true; while(head < tail) { point w = queue[head++]; if(w.x == k) { cout<<w.step<<endl; break; } if(w.x-1 >= 0 && !vist[w.x-1]) { vist[w.x-1] = true; queue[tail].x = w.x-1; queue[tail++].step = w.step+1; } if(w.x <= k && !vist[w.x+1]) { vist[w.x+1] = true; queue[tail].x = w.x+1; queue[tail++].step = w.step+1; } if(w.x <= k && !vist[2*w.x]) { vist[2*w.x] = true; queue[tail].x = 2*w.x; queue[tail++].step = w.step+1; } } return; } int main() { while(cin>>n>>k) { memset(vist,false,sizeof(vist)); bfs(); } return 0; }
相关文章推荐
- poj3278——Catch That Cow
- poj 3278 Catch That Cow
- POJ 3278: Catch That Cow
- poj 3278 Catch That Cow bfs
- ♥POJ 3278-Catch That Cow【搜索】
- poj3278 Catch That Cow BFS
- Poj 3278 Catch That Cow
- POJ 3278 Catch That Cow (BFS)
- POJ3278——Catch That Cow
- POJ 3278 Catch That Cow
- POJ 3278 Catch That Cow(追赶母牛)
- POJ 3278 Catch That Cow
- POJ 3278 Catch That Cow
- POJ-3278 Catch That Cow
- [POJ 3278]Catch That Cow[BFS]
- POJ3278——Catch That Cow
- poj3278——Catch That Cow
- Poj 3278 Catch That Cow
- POJ - 3278 Catch That Cow
- poj 3278 Catch That Cow