hdu 5361 2015多校联合训练赛#6 最短路
来源:互联网 发布:linux删除文件夹还存在 编辑:程序博客网 时间:2024/06/05 03:06
In Touch
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 67 Accepted Submission(s): 11
Problem Description
There are n soda living in a straight line. soda are numbered by 1,2,…,n from left to right. The distance between two adjacent soda is 1 meter. Every soda has a teleporter. The teleporter of i -th soda can teleport to the soda whose distance between i -th soda is no less than li and no larger than ri . The cost to use i -th soda's teleporter is ci .
The1 -st soda is their leader and he wants to know the minimum cost needed to reach i -th soda (1≤i≤n) .
The
Input
There are multiple test cases. The first line of input contains an integer T , indicating the number of test cases. For each test case:
The first line contains an integern (1≤n≤2×105) , the number of soda.
The second line containsn integers l1,l2,…,ln . The third line contains n integers r1,r2,…,rn . The fourth line contains n integers c1,c2,…,cn . (0≤li≤ri≤n,1≤ci≤109)
The first line contains an integer
The second line contains
Output
For each case, output n integers where i -th integer denotes the minimum cost needed to reach i -th soda. If 1 -st soda cannot reach i -the soda, you should just output -1.
Sample Input
152 0 0 0 13 1 1 0 51 1 1 1 1
Sample Output
0 2 1 1 -1HintIf you need a larger stack size, please use #pragma comment(linker, "/STACK:102400000,102400000") and submit your solution using C++.
Source
2015 Multi-University Training Contest 6
求最短路:把一个集合的点看做是一个点,这样就可以用djstra算法做了。然后由于每个点最多标记一次最短路,用set维护一个点集合。
当最短路找到一个一个集合的时候,把这个集合里还存在的点都取出即可。取出后,每个点又可以去两个集合,
再向保存最短路的set里更新集合信息即可。详细看代码。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<set>using namespace std;#define maxn 200007#define ll long longint lp[maxn],rp[maxn];ll cosw[maxn];ll dist[maxn];set<int> haha;struct Node{ int id; ll cost;};bool operator < (Node a,Node b){ if(a.cost == b.cost) return a.id < b.id; return a.cost < b.cost;}set<Node> mind;int main(){ int t,n; scanf("%d",&t); while(t--){ scanf("%d",&n); for(int i = 0;i < n; i++) scanf("%d",&lp[i]); for(int i = 0;i < n; i++) scanf("%d",&rp[i]); for(int i = 0;i < n; i++) scanf("%d",&cosw[i]); haha.clear(); mind.clear(); memset(dist,-1,sizeof(dist)); dist[0] = 0; Node x,y; x.id = 0; x.cost = cosw[0]; mind.insert(x); for(int i = 1;i < n; i++) haha.insert(i); set<int>::iterator it,it2; while(mind.size() > 0){ x = *mind.begin(); mind.erase(mind.begin()); it = haha.lower_bound(x.id - rp[x.id]); while(it != haha.end() && *it <= x.id - lp[x.id]){ y.id = *it; y.cost = x.cost + cosw[y.id]; dist[y.id] = x.cost; mind.insert(y); it2 = it++; haha.erase(it2); } it = haha.lower_bound(x.id + lp[x.id]); while(it != haha.end() && *it <= x.id + rp[x.id]){ y.id = *it; y.cost = x.cost + cosw[y.id]; dist[y.id] = x.cost; mind.insert(y); it2 = it++; haha.erase(it2); } } for(int i = 0;i < n; i++){ if(i) printf(" "); printf("%I64d",dist[i]); } printf("\n"); } return 0;}
0 0
- hdu 5361 2015多校联合训练赛#6 最短路
- HDU 5294 Tricks Device (最短路变体) 2015多校联合第一场
- hdu 5326 work 搜索 2015多校联合训练赛
- hdu 5417 RGCDQ 2015多校联合训练赛
- hdu 5387 Clock 2015多校联合训练赛#8
- hdu 5406 2015 多校联合训练赛#10 dp
- hdu 5358 First One 2015多校联合训练赛#6 枚举
- hdu 5362 Just A String 2015多校联合训练赛#6 动态规划
- 多校联合训练4&&HDU 5763
- 多校联合训练7&&HDU 5810
- 多校联合训练8&&HDU 5828
- hdu 5303 Delicious Apples 2015多校联合训练赛2 dp+枚举
- hdu 5338 ZZX and Permutations 2015多校联合训练赛,贪心,线段树,树状数组
- hdu 5327 Olympiad 简单题 2015多校联合训练赛
- hdu 5328 Problem Killer 2015多校联合训练赛4 简单题
- hdu 5330 Route Statistics 2015多校联合训练赛4 状态压缩
- hdu 5347 MZL's chemistry 2015多校联合训练赛#5 打表
- hdu 5348 MZL's endless loop 2015多校联合训练赛#5 找环+dfs
- HDOJ Kiki & Little Kiki 2 2276【位运算+矩阵快速幂】
- 手机网页摇一摇问题
- 关于坚持与凝聚力
- Hdoj 3790 最短路径问题
- QT 总结(一)(1.某位设1或0 2.加载dll、lib库 3.char * 转换为 wchar_t * 4.textBrowser 显示乱码 追加 5.checkBox的使能)
- hdu 5361 2015多校联合训练赛#6 最短路
- Java IO流--字符流
- Learning!数组|Array
- Curl状态码列表
- android中使用LocationManager定位获取信息
- 【web基础2】别老打开百度了,自己做一个试试?
- Restlet学习
- python实现二维数组
- HDU 5360 Hiking(优先队列)2015 Multi-University Training Contest 6