In Touch

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 67    Accepted Submission(s): 11

Problem Description
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.
 
Sample Input
1
5
2 0 0 0 1
3 1 1 0 5
1 1 1 1 1
 
Sample Output
0 2 1 1 -1
Hint
If you need a larger stack size,
please use #pragma comment(linker, "/STACK:102400000,102400000") and submit your solution using C++.
 
Source

求最短路:把一个集合的点看做是一个点,这样就能够用djstra算法做了。然后因为每一个点最多标记一次最短路,用set维护一个点集合。

当最短路找到一个一个集合的时候,把这个集合里还存在的点都取出就可以。取出后。每一个点又能够去两个集合。

再向保存最短路的set里更新集合信息就可以。具体看代码。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
#define maxn 200007
#define ll long long int lp[maxn],rp[maxn];
ll cosw[maxn];
ll dist[maxn]; set<int> haha; struct Node{
int id;
ll cost;
};
bool operator < (Node a,Node b){
if(a.cost == b.cost) return a.id < b.id;
return a.cost < b.cost;
} set<Node> mind; int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i = 0;i < n; i++)
scanf("%d",&lp[i]);
for(int i = 0;i < n; i++)
scanf("%d",&rp[i]);
for(int i = 0;i < n; i++)
scanf("%d",&cosw[i]);
haha.clear();
mind.clear();
memset(dist,-1,sizeof(dist));
dist[0] = 0; Node x,y;
x.id = 0;
x.cost = cosw[0];
mind.insert(x);
for(int i = 1;i < n; i++)
haha.insert(i); set<int>::iterator it,it2;
while(mind.size() > 0){
x = *mind.begin();
mind.erase(mind.begin()); it = haha.lower_bound(x.id - rp[x.id]);
while(it != haha.end() && *it <= x.id - lp[x.id]){
y.id = *it;
y.cost = x.cost + cosw[y.id];
dist[y.id] = x.cost;
mind.insert(y);
it2 = it++;
haha.erase(it2);
} it = haha.lower_bound(x.id + lp[x.id]);
while(it != haha.end() && *it <= x.id + rp[x.id]){
y.id = *it;
y.cost = x.cost + cosw[y.id];
dist[y.id] = x.cost;
mind.insert(y);
it2 = it++;
haha.erase(it2);
}
}
for(int i = 0;i < n; i++){
if(i) printf(" ");
printf("%I64d",dist[i]);
}
printf("\n");
}
return 0;
}

hdu 5361 2015多校联合训练赛#6 最短路的更多相关文章

  1. HDU 5358(2015多校联合训练赛第六场1006) First One (区间合并+常数优化)

    pid=5358">HDU 5358 题意: 求∑​i=1​n​​∑​j=i​n​​(⌊log​2​​S(i,j)⌋+1)∗(i+j). 思路: S(i,j) < 10^10 & ...

  2. hdu 5381 The sum of gcd 2015多校联合训练赛#8莫队算法

    The sum of gcd Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

  3. hdu 5358 First One 2015多校联合训练赛#6 枚举

    First One Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  4. 2015多校联合训练赛 hdu 5308 I Wanna Become A 24-Point Master 2015 Multi-University Training Contest 2 构造题

    I Wanna Become A 24-Point Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 ...

  5. 2015多校联合训练赛hdu 5301 Buildings 2015 Multi-University Training Contest 2 简单题

    Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  6. HDU 5371 (2015多校联合训练赛第七场1003)Hotaru&#39;s problem(manacher+二分/枚举)

    pid=5371">HDU 5371 题意: 定义一个序列为N序列:这个序列按分作三部分,第一部分与第三部分同样,第一部分与第二部分对称. 如今给你一个长为n(n<10^5)的序 ...

  7. 2015多校联合训练赛 Training Contest 4 1008

    构造题: 比赛的时候只想到:前面一样的数,后面 是类似1,2,3,4,5,6....t这 既是:t+1,t+1...,1,2,3,...t t+1的数目 可能 很多, 题解时YY出一个N 然后对N   ...

  8. hdu 5288||2015多校联合第一场1001题

    pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...

  9. HDU OJ 5317 RGCDQ( 2015多校联合训练第3场) 暴力打表+小技巧

    题目连接:Click here 题意:在一个[L,R]内找到最大的gcd(f[i],f[j])其中L<=i<j<=R,f[x]表示i分解质因数后因子的种类数.eg:f[10]=2(1 ...

随机推荐

  1. PHP 下基于 php-amqp 扩展的 RabbitMQ 简单用例 (四) -- Push API 和 Pull API

    RabbitMQ 中针对消息的分发提供了 Push API (订阅模式) 和 Pull API (主动获取) 两种模式. 在 PHP 中, 这两种模式分别通过 AMQPQueue 类中的 consum ...

  2. C++ 指针形参和指针引用形参的原理分析

    C++ 函数的参数传递可以分为:值传递和引用传递. 两者的最大区别也很简单,如果该函数的参数只是读的话,值传递就可以满足.如果该函数的参数需要进行修改并返回的时候,就应该进行引用传递. C++指针作为 ...

  3. 处理半连接SQL自动改写内连接SQL一例

    昨天刚写了半连接改写系列,今天就遇到了此类型SQL: 优化前 耗时:28s 返回:0 SELECT D.DAILYAUDITNO, D.TRANSTOACC FROM PB_DOIC.MM_DAILY ...

  4. HDU 4747 Mex【线段树上二分+扫描线】

    [题意概述] 一个区间的Mex为这个区间没有出现过的最小自然数,现在给你一个序列,要求求出所有区间的Mex的和. [题解] 扫描线+线段树. 我们在线段树上维护从当前左端点开始的前缀Mex,显然从左到 ...

  5. DFS求连通块(漫水填充法)

    G - DFS(floodfill),推荐 Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I6 ...

  6. Python+selenium下拉菜单选项

    案例:在我要自学网登录页面选择要保留的时间 具体页面如图所示: 使用前端工具查看部分页面代码: <select class="loinp" name="Cookie ...

  7. 安装eclipse插件,很慢终于找到了解决的方法

    1 .除非你需要,否则不要选择"联接到所有更新站点" 在安装对话框里有一个小复选框,其标示为"在安装过程中联接到所有更新站点从而找到所需的软件."从表面上看,这 ...

  8. 删除右键open foler as pycharm project(WIN10)

    1.打开注册表(WIN+R 输入regedit) 2.找到 HKEY_CLASSES_ROOT\Directory\Background 路径 下找到Parcharm文件夹,删除,右键的open fo ...

  9. OpenCV在Linux(Fedora)下搭建开发环境简述

    盼望了好久的Fedora21终于发行了.先来晒一张图: 默认桌面还是那么简洁: 好了,废话少说.来看看在Fedora下搭建opencv开发环境,因为我已经搭建好了(过程比较艰辛) 先注明参考文章,感谢 ...

  10. 在子线程中更新UI,只能使用Handler

    package com.pingyijinren.test; import android.os.Handler; import android.os.Message; import android. ...