原题网址: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. JAVA常见算法题(十七)

    package com.xiaowu.demo; //输出九九乘法表. public class Demo17 { public static void main(String[] args) { t ...

  2. .Net程序测试阿里云OSS开放存储服务

    阿里云官网有提供OSS相关的操作API文档和.Net程序的 SDK,也可以在这里下载OSS相关文件 但是API文档里面的都是通过http请求和响应的消息来描述如何操作OSS的 而一般在程序中需要的是O ...

  3. 转: MyEclipse 10.0,9.0,8.0 下添加jadClipse反编译插件

    MyEclipse 10.0,9.0,8.0 下添加jadClipse反编译插件 (2012-11-19 15:36:35) 转载▼ 标签: myeclipse jad 反编译 插件 it 分类: M ...

  4. ACdreamoj 1011(树状数组维护字符串hash前缀和)

    题目链接:http://acdream.info/problem? pid=1019 题意:两种操作,第一种将字符串某个位置的字符换为还有一个字符.另外一种查询某个连续子序列是否是回文串: 解法:有两 ...

  5. Java BaseDao

    BaseDao类: package dao; import java.sql.*; public class BaseDao { private static final String driver ...

  6. windows新建或者重命名文件及目录必须手动刷新才干显示出来问题解决方法

     首先推断注冊表中HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Update\UpdateMode值是否为0,该值若为1表示手工刷新, 该 ...

  7. linux 设置时间

    1.图形界面里面点击右上角的 “时间” 2.设置,edit 找到china G8区 date发现还没有生效 3.reboot 重启才生效了

  8. 【Excle数据透视表】如何在组的顶部显示分类汇总

    调整前                                                                                     调整后        例 ...

  9. Java Learning Path(四) 方法篇

    Java Learning Path(四) 方法篇 Java作为一门编程语言,最好的学习方法就是写代码.当你学习一个类以后,你就可以自己写个简单的例子程序来运行一下,看看有什么结果,然后再多调用几个类 ...

  10. ajax读取文件内容

    读取json文件 $.ajax({ url: 'manifest.webapp', type: 'GET', dataType: 'json',//类型不对会出错 timeout: 1000, //设 ...