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 ...
随机推荐
- python 在爬虫中timeout设置超时有什么作用
是为了防止url不可访问,或者响应速度太慢而造成的时间浪费. 比如,你要爬取1000个网站,如果有100个需要30s才能返回数据,你等待他们返回的话就需要3000s了,如果你设置10s超时,那么就能知 ...
- hdu 1385 floyd记录路径
可以用floyd 直接记录相应路径 太棒了! http://blog.csdn.net/ice_crazy/article/details/7785111 #include"stdio.h& ...
- nyoj 20水
#include<stdio.h> #include<string.h> #define N 110000 struct node { int u,v,next; }bian[ ...
- [asp.net]ashx中session存入,aspx为null的原因(使用flash uploader)
I am using uploadify to upload files, they automatically post to the handler. I then modify the sess ...
- [Design]Adobe CS6 2%错误问题
错误描述:FATAL: Payload '{3F023875-4A52-4605-9DB6-A88D4A813E8D} Camera Profiles Installer 6.0.98.0' info ...
- hdu 2151
就是一个dp,数组内存的步数, 数组没清空,wa了一次 #include<cstdio> #include<algorithm> #include<cstring> ...
- c3---scanf
#include <stdio.h> int main(int argc, const char * argv[]) { // 要求: 存储用户输入的整数 // 1.用户输入的整数确定吗? ...
- LigerUI 单独调用插件使用注意项
LigerUI 再某些情况下只需要使用部分功能,并不需要调用 ligerui.all.js . 比喻: 我现在只想用ligerGrid功能 只需要调用 <link href="lige ...
- oracle RAC 11g sqlload 生产表导入数据(ORA-12899)
背景:由于即将来临的双十一,业务部门(我司是做京东,天猫的短信服务),短信入库慢,需要DBA把数据库sqlload进数据库. 表结构如下: MRS VARCHAR2(100), STATUS VARC ...
- struts2学习之基础笔记1
第6章 Strusts 2框架 1 引出 Web App àà MVC àà View 视图(jsp,html,JS) | C(Servlet)Filter,Listneer | M(数据bea ...