POJ 3278(BFS)
来源:互联网 发布:在线字体设计软件 编辑:程序博客网 时间:2024/05/29 10:18
题目链接:http://poj.org/problem?id=3278
特别水的一道BFS...
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespace std;const int INF=0x3f3f3f3f;const int maxn=100010;int T,n,m,k;int x[maxn];bool vis[maxn];struct node{int x;int step;};void bfs(){queue<node>q;node s,e;s.x=n,s.step=0;vis[s.x]=1;q.push(s);while(!q.empty()){s=q.front();q.pop();if(s.x==k){printf("%d\n",s.step);return ;}e.step=s.step+1;e.x=s.x-1;if(e.x>=0&&!vis[e.x]){vis[e.x]=1;q.push(e);}e.x=s.x+1;if(e.x<=100000&&!vis[e.x]){vis[e.x]=1;q.push(e);}e.x=2*s.x;if((e.x>=0&&e.x<=100000)&&!vis[e.x]){vis[e.x]=1;q.push(e);}}}int main(){#ifndef ONLINE_JUDGEfreopen("test.in","r",stdin);freopen("test.out","w",stdout);#endifwhile(~scanf("%d%d",&n,&k)){memset(vis,0,sizeof(vis));bfs();}return 0;}
0 0
- POJ 3278(BFS)
- POJ - 3278(BFS)
- POJ 3278(bfs)
- poj 3278 cow (bfs)
- BFS专攻:POJ 3278 (三个方向的简单BFS)
- !POJ 3278 Catch That Cow--BFS(隐蔽的BFS)
- poj 3278 Catch That Cow(bfs)
- POJ 3278(BFS-搜索范围)
- POJ 3278 Catch That Cow (BFS)
- POJ 3278 Catch That Cow(BFS)
- poj 3278 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)
- delphi imagen usb vid&pid
- Google Chrome浏览器调试
- eclpise热加载,不用重启tomcate
- spring-mvc最小化配置,最简单入门。
- java.lang.RuntimeException: Parcelable encountered IOException writing serializable object
- POJ 3278(BFS)
- iOS BSD socket编程
- Java反射获取类的属性值和方法
- 利用c语言代码打印一个心形(带立体感)
- rsyncd 同步
- 如何创建UIlabel,使label的高度随着内容的多少而变动并且可以设置行间距?
- Java提高篇(二八)------TreeSet
- 论文中的定理(Theorem)、引理(Lemma)、推论(Corollary)
- C++内存布局一