Poj 1724 ROADS (搜索 最短路 BFS优先队列)
来源:互联网 发布:剑三正太捏脸数据导入 编辑:程序博客网 时间:2024/05/18 01:45
题意:有n 城市,r条路,有k这么多的钱。每条路都有长度和花费两个参数,求从1到n最短且总花费不超过k的长度。
思路:优先队列。每次将长度最小的出队,然后判断花费,位超限就将后继点入队。
#include <cstdio>#include <cstring>#include <queue>using namespace std;int n,k,r,e;int head[105];struct Edges{ int v,c,l,next;}edge[10005];struct Node{ int u,cost,len; Node (int _u,int _c, int _l) {u=_u,cost=_c,len=_l; }bool operator < (const Node& b) const {return len>b.len;}};void Addedge (int u, int v, int len, int cost){edge[e].next = head[u];edge[e].v = v;edge[e].l = len;edge[e].c = cost;head[u] = e++;}int Deal (){priority_queue<Node> q;q.push(Node(1,0,0));while (!q.empty()){Node temp = q.top();q.pop();if (temp.u == n)return temp.len;for (int i=head[temp.u];i != -1; i=edge[i].next)if (temp.cost + edge[i].c <= k)q.push (Node(edge[i].v,temp.cost+edge[i].c,temp.len+edge[i].l));}return -1;}int main (){scanf("%d%d%d",&k,&n,&r);e=0; memset(head,-1,sizeof(head));for (int i=0; i<r;i++) {int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);Addedge(a,b,c,d);}printf("%d\n",Deal ());return 0;}
- Poj 1724 ROADS (搜索 最短路 BFS优先队列)
- POJ 1724 ROADS 最短路 邻接表 + bfs +优先队列
- POJ 1724ROADS(费用最短路:优先队列+BFS)
- 【poj 1724】 ROADS 最短路(dijkstra+优先队列)
- POJ 1724 ROADS (优先队列+BFS)
- POJ 1724 ROADS(BFS + 优先队列)
- POJ 1724 ROADS(bfs最短路)
- POJ-1724-ROADS(优先队列,邻接表,BFS)
- POJ 1724 ROADS(领接链表的BFS+优先队列)
- POJ ROADS DFS BFS 优先队列 入门
- POJ 1724 ROADS 有约束的最短路问题, BFS
- POJ 1724 ROADS 最短路
- poj3635-DP+优先队列搜索最短路
- hdu1428漫步校园( 最短路+BFS(优先队列)+记忆化搜索(DFS))
- HDU 1248 漫步校园 (优先队列+BFS求最短路+记忆化搜索)
- POJ 1724 优先队列解带限制最短路
- poj 1724 最短路+优先队列(两个约束条件)
- poj --- 1724 最短路变形 【Dij + 优先队列 】
- 201103
- velocty+vm word模板导出word乱码问题解决
- mpeg2
- 关于百度地图API的lib包的记录
- 201009
- Poj 1724 ROADS (搜索 最短路 BFS优先队列)
- Zero Clipboard - 跨浏览器兼容的“复制到剪贴板”功能
- 201003
- 如何打造像样的应用日志——10条秘诀
- 200910
- Shell 获取当前执行脚本的路径
- 200906
- 黑马程序员 面对对象(二)
- zip打包,unzip解包