简单的BFS A strange lift
来源:互联网 发布:oracle数据库多少钱 编辑:程序博客网 时间:2024/05/21 11:25
有点疑惑,这个题目用DFS和bfs在时间复杂度上面有什么区别吗?
先把BFS的保存下来,自己写个DFS看下
#include<stdio.h>#include<string.h>#define Max 10000typedef struct node{int step;int ceng;}position;typedef struct {int head,tail;struct node a[Max];}queue;bool visited[205];void create(queue&);void enqueue(position,queue&);position dequeue(queue&);bool empty(queue&);int bfs(int ,int ,int ,int []);int main(){int n,m,v,i,b[205],k;while(scanf("%d",&n)&&n){memset(visited,0,sizeof(visited));scanf("%d %d",&m,&v);for(i=1;i<=n;i++)scanf("%d",&b[i]);if(v==m){printf("0\n");continue;}k=bfs(n,m,v,b);printf("%d\n",k);}return 0;}int bfs(int n,int m,int v,int b[]){position now,next;queue q;create(q);now.ceng=m;now.step=0;enqueue(now,q);while(!empty(q)){visited[now.ceng]=true;now=dequeue(q);next.ceng=now.ceng+b[now.ceng];next.step=now.step+1;if(next.ceng==v)return next.step;else if(next.ceng<=n&&next.ceng>0&&!visited[next.ceng]) {enqueue(next,q);}next.ceng=now.ceng-b[now.ceng];if(next.ceng==v){return next.step;}else if(next.ceng<=n&&next.ceng>00&&!visited[next.ceng]){enqueue(next,q);}}return -1;}void create(queue&q){q.head=q.tail=0;}void enqueue(position p,queue&q){q.a[q.tail]=p;q.tail=(q.tail+1)%Max;}position dequeue(queue&q){position p;p=q.a[q.head];q.head=(q.head+1)%Max;return p;}bool empty(queue&q){if(q.head==q.tail) return true;else return false;}
- 简单的BFS A strange lift
- A strange lift(简单BFS)
- hdu1548 A strange lift (简单bfs)
- 简单bfs HDU a strange lift
- HDU 1548 A strange lift (简单BFS)
- A strange lift(BFS)
- A strange lift【BFS】
- hdu1548 [A strange lift] bfs
- HDU1548:A strange lift(BFS)
- HDU1548:A strange lift( BFS)
- HDU-a strange lift-BFS
- hdu1548 A strange lift(bfs)
- HDU1548:A strange lift(BFS)
- hdu1548-A strange lift BFS
- BFS入门-A strange lift
- A strange lift HDU 1548 queue BFS 简单 水题
- HDU 1548 A strange lift (简单最短路或BFS)
- HDU 1548 A strange lift(简单BFS)
- AsyncTask与Handler的区别
- java data
- ASP.Net超时时间已到解决办法-
- ASP.NET MVC-- 在网页上显示一个时钟
- 同时有SQL2000和2005共存,连接2005时提示 无效连接
- 简单的BFS A strange lift
- ATL TRACE
- linux--多线程--面试题
- 【Linux】Linux 下socket 编程
- Spring mvc (一) [从请求页到控制器到结果页的简单实现案例]
- CPU性能衡量参数-主频,MIPS,CPI,时钟周期,机器周期,指令周期
- 雷锋读图:舌尖上的科技
- 视图
- AODV路由维护(定期发送Hello和链路层反馈)