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 ...
随机推荐
- Elasticsearch架构原理
架构原理 本书作为 Elastic Stack 指南,关注于 Elasticsearch 在日志和数据分析场景的应用,并不打算对底层的 Lucene 原理或者 Java 编程做详细的介绍,但是 Ela ...
- Struts2校验
struts2校验有两种实现方法: 手工编写代码实现(基本验证) //login.jsp <font color="red"><s:fielderror/> ...
- C#中的DES加密
publicstaticstringEncryptString(string sInputString,string sKey,string sIV) { try { byte[] data =Enc ...
- 使用angularjs的$http.post异步提交数据时,服务器接收不了的问题
一,在正常情况下,使用表单的post方法提交数据,默认请求头的Content-Type:application/x-www-form-urlencoded类型, 提交数据格式如下: 二,使用angul ...
- valueof这个万能方法,将string转换为int或者int转换为string都可以
private static String testString = "111"; int stringInt = Integer.valueOf(testString); Str ...
- 用户体验之如何优化你的APP
用户体验,速度为王,来几个优化APP“速度”的建议. 1.后台执行 毋庸多言,已是通常做法. 一般在执行下载任务时让其在后台运营,让用户有精力去做别的事情. 后端加载 2.提前显示 客户端与WEB的数 ...
- WifiManager类具体解释
public class WifiManager extends Object java.lang.Object ↳ android.net.wifi.WifiManager 类概述 This ...
- [学习笔记—Objective-C]《Objective-C-基础教程 第2版》第十一章 属性
11.1 使用属性值 @property float rainHandling; //表明此类具有float类型的属性,其名称为rainHandling 注意:属性的名称不必与实例变量名称同样. @s ...
- UVA - 1642 Magical GCD 数学
Magical GCD The Magical GCD of a nonempty sequence of positive integer ...
- uninstall OpenJDK9
sudo apt--jre openjdk--jdk ///要慎用auto命令,会把所有的软件包删掉 https://www.linuxidc.com/Linux/2017-11/148941.htm ...