uestc 482 Charitable Exchange 广搜+优先队列优化
来源:互联网 发布:mac怎么玩魔兽争霸 编辑:程序博客网 时间:2024/06/05 00:29
用优先队列对花费时间进行从大到小排序
#include<bits/stdc++.h>using namespace std;const int N=100000+1;typedef long long ll;struct edge{ ll u,v,w;}g[N];struct node{ ll m,t; friend bool operator <(node n1,node n2) { return n2.t<n1.t; }};int n;int cmp(edge a,edge b){ return a.v<b.v;}ll bfs(ll m){ int i,st=0; priority_queue<node>pq; node o,p; p.m=1; p.t=0; pq.push(p); while(!pq.empty()) { p=pq.top(); pq.pop(); if(p.m>=m) return p.t; for(i=st;i<n;i++) { if(g[i].v>p.m) break; if(g[i].u<=p.m) continue; o.m=g[i].u; o.t=p.t+g[i].w; pq.push(o); } st=i; } return -1;}int main(){ int _,i,cas=0; ll m; scanf("%d",&_); while(_--) { scanf("%d%lld",&n,&m); for(i=0;i<n;i++) scanf("%lld%lld%lld",&g[i].u,&g[i].v,&g[i].w); sort(g,g+n,cmp); printf("Case #%d: %lld\n",++cas,bfs(m)); } return 0;}
0 0
- uestc 482 Charitable Exchange 广搜+优先队列优化
- UESTC 482 Charitable Exchange(优先队列+bfs)
- UESTC 482 Charitable Exchange
- UESTC 482 Charitable Exchange (线段树)
- UESTC 1558 Charitable Exchange
- UESTC 1558 Charitable Exchange
- 最短路,前缀和优化连边,Dijkstra(UESTC 482,Charitable Exchange)
- 四川省ACM省赛B题,优先队列+BFS Charitable Exchange
- UESTC 482 Charitable Exchange(四川省赛B题)
- 广搜+优先队列
- UESTC_1558 Charitable Exchange 弦断树优化dp
- hdu1242 广搜+优先队列
- hdu1026 优先队列+广搜
- Hduoj1242【广搜+优先队列】
- Hduoj1026【广搜+优先队列】
- Rescue 优先队列+广搜
- poj1724_ROADS(优先队列广搜)
- *【UESTC】优先队列
- caffe中mnist数据集的运行
- 在Eclipses中查看JDK源码的方法
- 线程创建函数pthread_create
- Linux Makefile try-run
- android 音量调整
- uestc 482 Charitable Exchange 广搜+优先队列优化
- 顺序栈,链栈,多栈运算
- 搭建hadoop2.5.2/Ubuntu12集群(完全分布式)
- java保留两位小数
- 我的梦想靠坚持
- 从源码角度分析android事件分发处理机制
- 百钱买百鸡问题
- 天堂和地狱
- 论开放与闭合