[POJ - 3278 ]Catch That Cow
Posted vikyanite
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[POJ - 3278 ]Catch That Cow相关的知识,希望对你有一定的参考价值。
还是很简单的水题。不过他的边界条件我到现在还是不是很懂hhhh
#include <cstdio> #include <queue> #include <cstring> using namespace std; struct position int x; int min; ; queue <position> q; int vis[100001]; int main() position man, temp; int start, end; while(~scanf("%d%d", &start, &end)) memset(vis, 0, sizeof(vis)); while(!q.empty()) q.pop(); man.x = start; man.min = 0; q.push(man); vis[man.x]=1; while(!q.empty()) man = q.front(); q.pop(); if(man.x == end) printf("%d\n", man.min); break; temp.x = man.x+1; if(temp.x>=0 && temp.x<=100000 && !vis[temp.x]) temp.min = man.min +1; vis[temp.x] =1 ; q.push(temp); temp.x = man.x-1; if(temp.x>=0 && temp.x<=100000 && !vis[temp.x]) temp.min = man.min +1; vis[temp.x] =1 ; q.push(temp); temp.x = man.x*2; if(temp.x>=0 && temp.x<=100000 && !vis[temp.x]) temp.min = man.min +1; vis[temp.x] =1 ; q.push(temp); return 0;
以上是关于[POJ - 3278 ]Catch That Cow的主要内容,如果未能解决你的问题,请参考以下文章
POJ 3278 - Catch That Cow - [BFS]