hdu 1548 A strange lift(优先队列)
来源:互联网 发布:淘宝卖变声软件吗 编辑:程序博客网 时间:2024/05/22 12:24
简单的优先队列,原来没学觉得还是不好做(貌似原来题目都没咋搞懂!!!)
今早遇见果断拿下!!!
清早水一道吧!(再过两天想回家看看,集训一个多月了,咋说呢!说累不累,就是不想了!!!)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
(废话:优先队列就是好用啊!优先!!!在这个世界大多数问题都是最值问题,要么最差,要么最好,呵呵,而优先队列无疑是不错的哦!嘿嘿·······)
#include<stdio.h>
#include<string.h>#include<queue>
using namespace std;
int start,end,n;
int a[500],visit[500];
struct node
{
int x,time;
friend bool operator<(node a,node b)
{
return a.time>b.time;
}
};
int dfs()
{
priority_queue<node>q;
node cur,next;
cur.x=start;
cur.time=0;
q.push(cur);
visit[start]=1;
while(!q.empty())
{
next=q.top();
q.pop();
if(next.x==end)
return next.time;
if(next.x+a[next.x]<=n&&visit[next.x+a[next.x]]==0)
{
cur.time=next.time+1;
cur.x=next.x+a[next.x];
q.push(cur);
visit[next.x+a[next.x]]=1;
}
if(next.x-a[next.x]>=1&&visit[next.x-a[next.x]]==0)
{
cur.time=next.time+1;
cur.x=next.x-a[next.x];
q.push(cur);
visit[next.x-a[next.x]]=1;
}
}
return -1;
}
int main()
{
int i,ans;
while(scanf("%d",&n),n)
{
memset(visit,0,sizeof(visit));
scanf("%d%d",&start,&end);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
ans=dfs();
printf("%d\n",ans);
}
return 0;
}
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1548
- hdu 1548 A strange lift(优先队列)
- A strange lift宽度搜索优先队列
- hdu 1548 A strange lift (bfs)
- HDU 1548 A strange lift(BFS)
- HDU 1548 A strange lift(bfs)
- hdu 1548 A strange lift(bfs)
- hdu 1548 A strange lift(BFS)
- hdu 1548 A strange lift (BFS)
- HDU - 1548 A strange lift(Dijkstra)
- hdu 1548 A strange lift(BFS)
- HDU 1548 A strange lift(bfs)
- HDU 1548:A strange lift(BFS)
- hdu-1548-A strange lift(bfs)
- A strange lift hdu 1548
- HDU 1548 A strange lift
- HDU 1548 A strange lift
- HDU 1548 A strange lift
- Hdu-1548 A strange lift
- SVM入门(二)线性分类器Part 1
- axis2 和spring整合
- Windows 文件过滤驱动经验总结
- 如何在DELPHI中操作EXCEL电子表格
- spring bean parent属性详解
- hdu 1548 A strange lift(优先队列)
- 求1^k+2^k+...+n^k ZOJ 2865
- IoCompleteRequest函数
- 学习dpkt-ip.py
- cvFindContours之轮廓个数
- 初识ADO.NET
- python 高手进阶学习资料
- 如何打jar包
- 记录代码——归并排序