hdu 5361 2015多校联合训练赛#6 最短路
In Touch
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 67 Accepted Submission(s): 11
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.
The 1-st
soda is their leader and he wants to know the minimum cost needed to reach i-th
soda (1≤i≤n).
indicating the number of test cases. For each test case:
The first line contains an integer n (1≤n≤2×105),
the number of soda.
The second line contains n 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)
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.
1
5
2 0 0 0 1
3 1 1 0 5
1 1 1 1 1
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++.
求最短路:把一个集合的点看做是一个点,这样就能够用djstra算法做了。然后因为每一个点最多标记一次最短路,用set维护一个点集合。
当最短路找到一个一个集合的时候,把这个集合里还存在的点都取出就可以。取出后。每一个点又能够去两个集合。
再向保存最短路的set里更新集合信息就可以。具体看代码。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
#define maxn 200007
#define ll long long int 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;
}
hdu 5361 2015多校联合训练赛#6 最短路的更多相关文章
- HDU 5358(2015多校联合训练赛第六场1006) First One (区间合并+常数优化)
pid=5358">HDU 5358 题意: 求∑i=1n∑j=in(⌊log2S(i,j)⌋+1)∗(i+j). 思路: S(i,j) < 10^10 & ...
- hdu 5381 The sum of gcd 2015多校联合训练赛#8莫队算法
The sum of gcd Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
- hdu 5358 First One 2015多校联合训练赛#6 枚举
First One Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
- 2015多校联合训练赛 hdu 5308 I Wanna Become A 24-Point Master 2015 Multi-University Training Contest 2 构造题
I Wanna Become A 24-Point Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 ...
- 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题
Buildings Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
- HDU 5371 (2015多校联合训练赛第七场1003)Hotaru's problem(manacher+二分/枚举)
pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序 ...
- 2015多校联合训练赛 Training Contest 4 1008
构造题: 比赛的时候只想到:前面一样的数,后面 是类似1,2,3,4,5,6....t这 既是:t+1,t+1...,1,2,3,...t t+1的数目 可能 很多, 题解时YY出一个N 然后对N ...
- hdu 5288||2015多校联合第一场1001题
pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...
- HDU OJ 5317 RGCDQ( 2015多校联合训练第3场) 暴力打表+小技巧
题目连接:Click here 题意:在一个[L,R]内找到最大的gcd(f[i],f[j])其中L<=i<j<=R,f[x]表示i分解质因数后因子的种类数.eg:f[10]=2(1 ...
随机推荐
- selenium click radio
radio = dr.find_element_by_xpath('//*[@id="contentTable"]/tbody/tr[1]/td[1]/input') webdri ...
- 将java project打包成jar包,web project 打包成war包的几种演示 此博文包含图片
转: http://blog.csdn.net/christine_ruan/article/details/7491559 http://developer.51cto.com/art/200907 ...
- js如何判断数组是Array类型
在说明如何判断一个对象为数组类型前,我们先巩固下js的数据类型,js一共有六大数据类型:number.string.object.Boolean.null.undefined.var str=&quo ...
- 洛谷——P2613 【模板】有理数取余
P2613 [模板]有理数取余 读入优化预处理 $\frac {a}{b}\mod 19620817$ 也就是$a\times b^{-1}$ $a\times b^{-1}\mod 19620817 ...
- [Luogu] P1156 垃圾陷阱
题目描述 卡门――农夫约翰极其珍视的一条Holsteins奶牛――已经落了到“垃圾井”中.“垃圾井”是农夫们扔垃圾的地方,它的深度为D(2≤D≤100)英尺. 卡门想把垃圾堆起来,等到堆得与井同样高时 ...
- web应用无法访问的原因之一以及如何设置数据库编码
这篇随笔,本是应该是在前天晚上发的,但是因为事情太多,硬生生拖到了现在,当时,在我将web应用部署到服务器上时,在调用接口时,客户端没有任何反应,应该是又出异常了,查看了控制台的异常输出,提示requ ...
- 建仓类型与对应建仓价MT4
建仓类型与对应建仓价 (Bid,Ask) 建仓类型 对应建仓价 Buy Ask+Spread Sell Bid-Spread BuyLimit Ask-Spread-StopLevel SellLim ...
- IOC&DI
[概述] 1.IOC(Inversion of Control): 即“反转控制”,不是什么技术,而是一种设计思想.其思想是反转资源获取的方向. 传统的资源查找方式要求组件向容器发起请求查找资源.作为 ...
- 【03】《论道html5》(全)
[03] <论道html5> 共320页. 魔芋:已看完. 读后感:html5各个新特性的介绍.介绍了canvas,web socket,audio,video,web wor ...
- HDU 5458 Stability
Stability Time Limit: 2000ms Memory Limit: 102400KB This problem will be judged on HDU. Original ID: ...