2016 acm香港网络赛 F.Crazy Driver

题目链接: https://vjudge.net/problem/Kattis-driver

 

题意:直线上有n个站点,每个站点间有一条路,这样就是n-1条,每条路都有一个过路费cost[i],

 

每个站点都有一个开放时间t[i],只有当前时间大于等于t[i]才能通过,
问在司机不停的情况下最少要花费多少通过所有站点(即如果当前门没开的话,司机是不会停的,还会继续跑)  

 

思路:在通过当前站点时,如果门没开,还需要的时间在之前花费最少的路上跑来回,答案就出来了。

 

 

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <set>
#define pi acos(-1.0)
#define LL long long
#define ULL unsigned long long
#define inf 0x3f3f3f3f
#define INF 1e18
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define debug(a) printf("---%d---\n", a)
#define mem0(a) memset(a, 0, sizeof(a))
#define memi(a) memset(a, inf, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
using namespace std;
typedef pair<int, int> P;
const double eps = 1e-10;
const int maxn = 100000+5;
const int mod = 1e8;

LL cost[maxn],t[maxn];
int main()
{
        int n;
        while(~scanf("%d",&n))
        {
            LL ans = 0;
            for(int i = 1 ; i < n ; i ++)
                    scanf("%lld",&cost[i]);
            for(int i = 0 ; i < n ; i ++)
                    scanf("%lld",&t[i]);
            LL cur = 0;
            LL mni = cost[1];
            for(int i = 1 ; i < n ; i ++)
            {
                mni = min(mni, cost[i]); // 前i条路长度最小的 
                if(cur+1 >= t[i]){ // 如果门开了 直接过 
                    cur++;
                    ans += cost[i];
                }
                else{  // 门没开  时间差值要分奇偶讨论 
                    LL tmp = t[i] - cur;
                    if (tmp % 2) {  // 奇数的话  (tmp-1)时间给最小的长度走  留1小时走cost[i]这条路 
                        ans += mni * (tmp-1) + cost[i]; // 这里是会爆 int的 
                        cur = t[i];
                    }
                    else {		// 偶数的话  就要多走一个小时 因为是往返的 
                        ans += mni * tmp + cost[i]; 
                        cur = t[i] + 1;
                    }
                }
            }
            printf("%lld\n",ans);
        }
        return 0;
}

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值