2016 acm香港网络赛 F题. Crazy Driver(水题)
原题网址:https://open.kattis.com/problems/driver
Crazy Driver
In the Linear City, there are N gates arranged in a straight line. The gates are labelled from 1 to N. Between adjacent gates, there is a bidirectional road. Each road takes one hour to travel and has a toll fee. Since the roads are narrow, you can only travel from gates to gates but cannot U-turn between gates.
Crazy driver Gary starts at Gate 1 at time 0 and he wants to drive through Gate N while minimizing the cost of travelling. However, Gate i only allows a car to pass through after a certain time Ti. As Gary is crazy, his car will always be traveling on any one of the roads, i.e., it will not stop at a gate. What is the minimum cost for him to drive through Gate N ?
As an example, consider the sample input below. An optimal solution is the following:
- Gate 1 to Gate 2 (cost 5)
- Gate 2 to Gate 1 (cost 5)
- Gate 1 to Gate 2 to Gate 3 (cost 9)
- Go between Gate 3 and Gate 4 until 7-th hour (cost 6)
- Go to and pass through Gate 5(cost 8)
Input
The first line contains an integer, N(2≤N≤105), the number of gates. The second line has N−1 integers, C1,…,CN−1. Ci (1≤Ci≤106) represents the toll fee of the road between Gate i and Gate i+1. The third line has N integers, T1,…,TN. Ti (0≤Ti≤106) represents the opening time (in hour) for each gate. T1 will always be 0.
Output
Output an integer representing the minimum cost of traveling.
Sample Input 1 |
Sample Output 1 |
5 5 4 2 8 0 2 4 4 8 |
33 |
题意:n个门编号1~n,从门i到i+1有一条双向通路,每条路花费的时间都是1小时,每条路花的路费分别是Ci, 每个门开的时刻分别是Ti,一个司机从门1开到门n,中间不停车,即如果到达门i的时候门没开就必须往返于前面的路上直到门开的时刻,问到门n最少花多少路费。
记录每扇门之前的路的最小路费。
#include <algorithm>
#include <cstring>
#include <string.h>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cstdio>
#include <cmath> #define LL long long
#define N 100005
#define INF 0x3ffffff using namespace std; int n;
int c[N]; //门i-1到门i的路费是Ci
int m[N]; //门i之前的路的路费最小值
int t[N]; //每个门开的时刻 int main()
{
scanf("%d",&n);
for(int i=;i<=n-;i++) {
scanf("%d",&c[i]);
if(i==) m[i]=c[i];
else m[i]=min(m[i-],c[i]);
}
for(int i=;i<n;i++) {
scanf("%d",&t[i]);
} int tt=; //当前时刻
int i=;
long long ret=;
while(i<n)
{
i++;
tt++;
ret+=(long long)(c[i]);
int tmp=t[i]-tt; //离门开还有多久 while(tmp>){
tmp-=;
ret+=(long long)(m[i]*);
tt+=;
}
}
cout<<ret<<endl;
return ;
}
2016 acm香港网络赛 F题. Crazy Driver(水题)的更多相关文章
- 2016 acm香港网络赛 C题. Classrooms(贪心)
原题网址:https://open.kattis.com/problems/classrooms Classrooms The new semester is about to begin, and ...
- 2016 acm香港网络赛 B题. Boxes
原题网址:https://open.kattis.com/problems/boxes Boxes There are N boxes, indexed by a number from 1 to N ...
- 2016 acm香港网络赛 A题. A+B Problem (FFT)
原题地址:https://open.kattis.com/problems/aplusb FFT代码参考kuangbin的博客:http://www.cnblogs.com/kuangbin/arch ...
- hihoCoder #1388 : Periodic Signal ( 2016 acm 北京网络赛 F题)
时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal processing. He has a device w ...
- hdu 5881 Tea (2016 acm 青岛网络赛)
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5881 Tea Time Limit: 3000/1000 MS (Java/Others) Me ...
- HDU 5901 Count primes (2016 acm 沈阳网络赛)
原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901 题意:输入n,输出n以内质数个数 模板题,模板我看不懂,只是存代码用. 官方题解链接:https ...
- 2018焦作网络赛 - Poor God Water 一道水题的教训
本题算是签到题,但由于赛中花费了过多的时间去滴吧格,造成了不必要的浪费以及智商掉线,所以有必要记录一下坑点 题意:方格从1到n,每一格mjl可以选择吃鱼/巧克力/鸡腿,求走到n格时满足 1.每三格不可 ...
- ACM-ICPC 2019南昌网络赛F题 Megumi With String
ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...
- 2016 年青岛网络赛---Family View(AC自动机)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5880 Problem Description Steam is a digital distribut ...
随机推荐
- Word中如何公式居中标号右对齐
1.鼠标居中 2.插入一行三列表格 3.选中第一个表格,右键-表格属性-单元格-选项:然后回到单元格设置垂直居中,宽度为15%,同理第三个单元格,不过中间单元格也要设置,宽度为70%,这个word没有 ...
- linux命令详解:cat命令
转:http://www.cnblogs.com/lwgdream/archive/2013/11/06/3409802.html 前言 cat命令用于读取文本文件,并且能够显示行号.特殊字符等. 使 ...
- linux mysql cluser集群
管理节点的安装与启动 config.init内容如下 [NDBD DEFAULT] NoOfReplicas=1 #定义在Cluster环境中相同数据的份数,最大为4 [NDB_MGMD] #设置管理 ...
- 【myEcplise2015】导入喜欢的主题
1.在官网下载epf样式文件 http://www.eclipsecolorthemes.org/ 2.选择一个喜欢的点击进入,点击下载 3.File -->Import--->Gener ...
- Java基础学习过程
转载:http://blog.csdn.net/scythe666/article/details/51699954JVM 1. 内存模型( 内存分为几部分? 堆溢出.栈溢出原因及实例?线上如何排查? ...
- python raise assert
class MyException(Exception): def __init__(self,error_msg): self.error_msg=error_msg def __str__(sel ...
- Python魔法师
第一章:数据结构和算法 1.1 查找最大或者最小的n个元素 heapq 模块的两个函数 nlargest() nsmallest() import heapq nums = [1, 8, 2, 23 ...
- MVVM模式源码分析手写实现
1.demo1.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- STL学习笔记(仿函数)
仿函数(Functors) 仿函数(functor),就是使一个类的使用看上去象一个函数.其实现就是类中实现一个operator(),这个类就有了类似函数的行为,就是一个仿函数类了. 例如我们定义一个 ...
- 【HTML5】元素<head>的使用
功能描述 在新建的页面<head>元素中,加入该元素所包含的各类标签,并定义超级链接的样式.当单击"请点击我"标签时,并展示相应效果并进入<base>元素设 ...