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 ...
随机推荐
- 0113针对大数据量SUM的优化-思路
转自博客:http://bbs.csdn.net/topics/390426801?page=1 优化思路:无论如何你的结果都是要扫描全有表记录,而在456010记录中,的UserName的分布导致这 ...
- asp.net mvc--传值-后台->前台
后台传值到前台的方式 Model Binding # 这是public ActionResult中的最后部分 return View(listmode); json方式01 public void G ...
- [Beginning SharePoint Designer 2010]Chapter5 主题和样式
本章概要: 1.什么是CSS 2.样式表的组成 3.如何管理CSS适应SPD的工具和特性 4.被SPS使用的关键的CSS类别 5.使用SPD应用样式到你的站点上
- 使用Dropzone上传图片及回显演示样例
一.图片上传所涉及到的问题 1.HTML页面中引入这么一段代码 <div class="row"> <div class="col-md-12" ...
- MySql 基础学习笔记 1——概述与基本数据类型: 整型: 1)TINYINT 2)SMALLINT 3) MEDIUMINT 4)INT 5)BIGINT 主要是大小的差别 图 浮点型:命令
一.CMD中经常使用mysql相关命令 mysql -D, --database=name //打开数据库 --delimiter=name //指定分隔符 -h, --host=name // ...
- java里面包的重要性-管理类文件
包的必要性 包是用来给java源文件分门别类的,java中一个包在windows下就是一个文件夹.包的全限定名是从根文件夹開始的(\src文件夹)以点号作为分隔符,包名和包名之间使用点号隔开,java ...
- 痛苦的人生——JRuby on Rails的开发与部署小记
最近单位领导部署了一项开发用户自助服务系统的任务,该任务有且仅有我一人独立完成——哈哈,十分美妙的工作呢. 恰巧楼主最近被Ruby的美妙特性所迷惑,于是义无反顾地投入到Ruby on Rails的怀抱 ...
- MongoDB在MacOS上的客户端Robo 3T 的简单使用(二)
最近写了一个用node来操作MongoDB完成增.删.改.查.排序.分页功能的示例,并且已经放在了服务器上地址:http://39.105.32.180:3333. 本篇文章只做简单介绍,能够使用起来 ...
- Centos上JDK的安装搭建
一.下载 yum search java|grep jdk //查找所有jdk版本 二.选择安装1.8 yum install java-1.8.0-openjdk-src-debug.x86_64 ...
- 将百度百科的机器学习词条中的一段关于机器学习的demo改用Java写了一遍
这是引用的百度百科中关于机器学习的一段示例,讲述了通过环境影响来进行学习的例子. 下面是代码: import java.io.BufferedReader; import java.io.IOExce ...