2015 Multi-University Training Contest 6 hdu 5361 In Touch
In Touch
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 578 Accepted Submission(s): 160
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.
The 1-st soda is their leader and he wants to know the minimum cost needed to reach i-th soda (1≤i≤n).
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 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)
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.
解题:利用set可以二分,进行dijkstra,思路是学习这位大神的,确实很赞,很厉害。。。。很奇妙
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
struct node{
int id;
LL cost;
node(int x = , LL y = ){
id = x;
cost = y;
}
bool operator<(const node &t)const{
if(cost == t.cost) return id < t.id;
return cost < t.cost;
}
};
set<int>p;
set<node>q;
int L[maxn],R[maxn],n;
LL w[maxn],d[maxn];
int main(){
int kase;
scanf("%d",&kase);
while(kase--){
scanf("%d",&n);
memset(d,-,sizeof d);
p.clear();
q.clear();
d[] = ;
for(int i = ; i < n; ++i){
scanf("%d",L + i);
if(i) p.insert(i);
}
for(int i = ; i < n; ++i)
scanf("%d",R + i);
for(int i = ; i < n; ++i)
scanf("%I64d",w + i);
q.insert(node(,w[]));
while(q.size()){
node cur = *q.begin();
q.erase(q.begin());
auto it = p.lower_bound(cur.id - R[cur.id]);
while(it != p.end() && *it <= cur.id - L[cur.id]){
d[*it] = cur.cost;
q.insert(node(*it,cur.cost + w[*it]));
p.erase(it++);
}
it = p.lower_bound(cur.id + L[cur.id]);
while(it != p.end() && *it <= cur.id + R[cur.id]){
d[*it] = cur.cost;
q.insert(node(*it,cur.cost + w[*it]));
p.erase(it++);
}
}
for(int i = ; i < n; ++i)
printf("%I64d%c",d[i],i + == n?'\n':' ');
}
return ;
}
2015 Multi-University Training Contest 6 hdu 5361 In Touch的更多相关文章
- Hdu 5361 In Touch (dijkatrs+优先队列)
题目链接: Hdu 5361 In Touch 题目描述: 有n个传送机排成一排,编号从1到n,每个传送机都可以把自己位置的东西传送到距离自己[l, r]距离的位置,并且花费c,问从1号传送机到其他 ...
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- 2015 Multi-University Training Contest 8 hdu 5385 The path
The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 2015 Multi-University Training Contest 6 hdu 5362 Just A String
Just A String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
随机推荐
- JavaScript实验一(添加节点,删除节点)
静态html页面: <!DOCTYPE html> <html> <head lang="en"> <meta charset=" ...
- Hadoop集群(第12期)_HBase简介及安装
HBase简介 HBase是Apache Hadoop的数据库,能够对大型数据提供随机.实时的读写访问,是Google的BigTable的开源实现.HBase的目标是存储并处理大型的数据,更具体地说仅 ...
- Java測试覆盖率工具----Cobertura,EclEmma
Cobertura 是一个与Junit集成的代码覆盖率測量工具 它是免费.开源的 它能够与Ant和Maven集成.也能够通过命令行调用 能够生成HTML或XML格式的报告 能够依照不同的标准对HTML ...
- Swift3.0 闭包整理
语法表达式 一般形式:{ (parameters) -> returnType in statements } 这里的参数 ...
- 英语发音规则---X字母
英语发音规则---X字母 一.总结 一句话总结: 1.x位于词尾或音节尾部,读/ks/? box /bɒks/ n.盒; 箱状物 fix /fɪks/ vt.固定 fox /fɒks/ n.狐; 狐狸 ...
- 【HDU 2176】 取(m堆)石子游戏
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2176 [算法] Nim博弈 当石子数异或和不为0时,先手必胜,否则先手必败 设石子异或和为S 如果 ...
- WCF:目录
ylbtech-WCF:目录 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http://ylbtech.c ...
- bfs初学
BFS: ** 当知道初始和目标状态的,用双向BFS: 无权图最好用BFS 不用重复如队** 实现框架: 抄来的(来源:https://www.luogu.org/blog/stephen2333/s ...
- ubuntu在桌面创建快捷方式
在/usr/share/applications下列出 *.desktop文件 例如: 首先查看所要创建的快捷方式有么有: ls /usr/share/applications | grep ecli ...
- Core篇——初探依赖注入
目录 1.DI&&IOC简单介绍 2.UML类图中六种关联关系 3..net core 中DI的使用 4..net core DI初始化源码初窥 DI&&IOC简单介绍 ...