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 ...
随机推荐
- oracle double和float,number
float,double,number都是oracle的数值类型.1个汉子=2个英文=2个字节float表示单精度浮点数在机内占4个字节,用32位二进制描述. double表示双精度浮点数在机内占8个 ...
- 全球级的分布式数据库 Google Spanner原理
开发四年只会写业务代码,分布式高并发都不会还做程序员?->>> Google Spanner简介 Spanner 是Google的全球级的分布式数据库 (Globally-Di ...
- POI 海量数据
http://blog.csdn.net/Little_Stars/article/details/8266262
- ASP.NET--identity笔记及截图
aspnetUsers aspnetRoles aspnetUserroles aspnetUserClaims 存储用户user额外信息的键值对 aspnetUserLogins 第三方登陆的控件 ...
- jqury+animation+setTimeOut实现渐变显示与隐藏动画
初始效果 实现效果 1,编写HTMl结构代码 <div class="box"> <i class="icon"></i> ...
- 【C++】通用单链表
在C++的学习中,採用模板类,而採用虚函数实现多态性.达到通用的目的.结点类数据域被改造为指针,而把数据放在一个抽象类中.由指针与之建立联系. 採用虚函数实现多态性,达到通用的目的.堆内存的分配与释放 ...
- BAT常问问题总结以及回答(问题汇总篇)
几个大厂的面试题目目录: java基础(40题)https://www.cnblogs.com/television/p/9397968.html 多线程(51题) 设计模式(8点) JVM(12题) ...
- 深入分析JavaWeb Item39 -- 监听器(Listener)学习进阶
一.监听域对象中属性的变更的监听器 域对象中属性的变更的事件监听器就是用来监听 ServletContext, HttpSession, HttpServletRequest 这三个对象中的属性变更信 ...
- android创建桌面快捷键shortcut
有非常多人也写过创建桌面快捷键的blog.可是大部分都仅仅讲了怎么用,事实上技术使用起来都非常easy.可是你使用后下次还知道吗? 根本原因还是不清楚原理.今天我就来讲讲shortcut创建过程. 过 ...
- XTU1202:逆序数
题目描写叙述 有n张卡片,分别标有数字1~n. 有一天Silence把他们按某种序列排好.然后从第一张開始取出一张,再拿一张放到最后面.再取出一张,再拿出一张放到最后面...知道n张卡片所有取走. 把 ...