原题网址: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. PowerPoint在线浏览的几个方案

    思路:将ppt转换成pdf.image后实现在线浏览功能 下面的解决方案均不用在服务器端安装office 一.找到一个收费的restful接口,测试可用 http://www.convertapi.c ...

  2. JAVA常见算法题(十四)

    package com.xiaowu.demo; /** * 输入某年某月某日,判断这一天是这一年的第几天? * * * @author WQ * */ public class Demo14 { p ...

  3. CURL简单使用

    学习地址:https://yq.aliyun.com/articles/33262 curl的简单使用步骤 要使用cURL来发送url请求,具体步骤大体分为以下四步: 1.初始化2.设置请求选项3.执 ...

  4. 矩阵十题【五】 VOJ1049 HDU 2371 Decode the Strings

    题目链接:https://vijos.org/p/1049 题目大意:顺次给出m个置换,重复使用这m个置换对初始序列进行操作.问k次置换后的序列.m<=10, k<2^31. 首先将这m个 ...

  5. mysql关于访问权限以及root密码修改

    root密码修改:mysql> use mysql;mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = ' ...

  6. 用MyEclipse2016 CI版创建一个SpringBoot程序

    之前先要在Eclipse里安装STS,步骤如下: 1.点击菜单Help->Install from Catalog 2.在弹出的对话框中点击Popular选项卡,在STS旁边点Install按钮 ...

  7. Service和Activity交互之广播方式

    一.使用场景如果要通知多个Activity,广播较为适合.但广播较为耗费性能. 二.Broadcast更新Activity中的UI 1.新建一个接口OnUpdateUI,用于回调更新UI public ...

  8. jmap命令(Java Memory Map)的使用

    jmap的使用能够參考: 官方文档 http://docs.oracle.com/javase/6/docs/technotes/tools/share/jmap.html 和这篇博客 http:// ...

  9. Oracle 日期总结

    一.带星期格式 .SELECT to_char(to_date('2014-12-12','yyyy-mm-dd'),'MM-DD (DAY)') FROM DUAL .SELECT to_char( ...

  10. (七)Thymeleaf的 th:* 属性之—— th: ->设值& 遍历迭代& 条件判断

    3.4 属性值的设置 3.4.1 使用th:attr来设置属性的值 <form action="subscribe.html" th:attr="action=@{ ...