原题网址: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(水题)的更多相关文章

  1. 2016 acm香港网络赛 C题. Classrooms(贪心)

    原题网址:https://open.kattis.com/problems/classrooms Classrooms The new semester is about to begin, and ...

  2. 2016 acm香港网络赛 B题. Boxes

    原题网址:https://open.kattis.com/problems/boxes Boxes There are N boxes, indexed by a number from 1 to N ...

  3. 2016 acm香港网络赛 A题. A+B Problem (FFT)

    原题地址:https://open.kattis.com/problems/aplusb FFT代码参考kuangbin的博客:http://www.cnblogs.com/kuangbin/arch ...

  4. hihoCoder #1388 : Periodic Signal ( 2016 acm 北京网络赛 F题)

    时间限制:5000ms 单点时限:5000ms 内存限制:256MB 描述 Profess X is an expert in signal processing. He has a device w ...

  5. hdu 5881 Tea (2016 acm 青岛网络赛)

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5881 Tea Time Limit: 3000/1000 MS (Java/Others)    Me ...

  6. HDU 5901 Count primes (2016 acm 沈阳网络赛)

    原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=5901 题意:输入n,输出n以内质数个数 模板题,模板我看不懂,只是存代码用. 官方题解链接:https ...

  7. 2018焦作网络赛 - Poor God Water 一道水题的教训

    本题算是签到题,但由于赛中花费了过多的时间去滴吧格,造成了不必要的浪费以及智商掉线,所以有必要记录一下坑点 题意:方格从1到n,每一格mjl可以选择吃鱼/巧克力/鸡腿,求走到n格时满足 1.每三格不可 ...

  8. ACM-ICPC 2019南昌网络赛F题 Megumi With String

    ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...

  9. 2016 年青岛网络赛---Family View(AC自动机)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5880 Problem Description Steam is a digital distribut ...

随机推荐

  1. vue axios跨域请求,apache服务器设置

    问题所在axios请求会发送两次请求 也就是说,它会先使用options去测试,你这个接口是否能够正常通讯,如果不能就不会发送真正的请求过来,如果测试通讯正常,则开始正常请求. 思路: 跨域--> ...

  2. tmux用法

    列出所有的tmux  session,一个session是多个窗口的集合 tmux list-session 创建tmux窗口, tmux new -s server server为tmux的sess ...

  3. DotnetBrowser高级教程-(5)使用内置的MVC UI框架-EasyMvc

    如果DotnetBrowser只是实现了内置chrome浏览器和web/web socket server,似乎还不是很完美.因此,最新的DotnetBrowser已经内置对easy mvc控件的支持 ...

  4. VBO与VAO 【转】

    我想大家都已经熟悉VBO了吧.在GL3.0时代的VBO大体还是处于最重要的地位,但是与此同时也出现了不少新的用法和辅助役,其中一个就是VAO.本文大致小记一下这两者的联系,帮助大家理解一下这个角色.— ...

  5. FormData上传文件同时附带其他参数

    前端js代码: function fileSubmit() { var formData = new FormData(); formData.append(].files[]); var type ...

  6. Linux alias理解及设置

    1.alias简介 Linux alias 是命令的一种别称,输入 alias 可以看到像下面这样的结果: alias l.='ls -d .* --color=auto' alias ll='ls ...

  7. hdu 5012 bfs --- 慎用STL 比方MAP判重

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 发现一个问题 假设Sting s = '1'+'2'+'3'; s!="123"!!! ...

  8. 遍历修改django bootstrap form 为 django bootstrap3

    #!/usr/bin/env python # encoding: utf-8 import re import os fname = '' bt_pattern = re.compile(r'{% ...

  9. CentOS——yum命令运行错误解决办法

    问题: [root@name user]# yum File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:        ...

  10. Vue mixins extend

    const mixins = { created () { console.log('mixins created') } } const mixins2 = { created () { conso ...