Road to Post Office

题意:

一个人要从0走到d,可以坐车走k米,之后车就会坏,你可以修或不修,修要花t时间,坐车单位距离花费a时间,走路单位距离花费b时间,问到d的最短时间。

题解:

首先要分成k段,k段的总长是ovmod,每一段可以选择修车坐车或选择走路,(只有第一段的时候不用修车),最后在加上剩下的那些路的时间,剩下的是mod,(可以选择修车坐车或选择走路)最后min答案就好了。但其中还有一种情况要注意,就是前ovmod也可以选择坐车之后不修走着,所以这种要特殊处理下。

代码:

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
#define PU puts("");
#define PI(A) cout<<A<<endl
#define SI(N) cin>>N
#define SII(N,M) cin>>N>>M
#define cle(a,val) memset(a,(val),sizeof(a))
#define rep(i,b) for(int i=0;i<(b);i++)
#define Rep(i,a,b) for(int i=(a);i<=(b);i++)
#define reRep(i,a,b) for(int i=(a);i>=(b);i--)
#define dbg(x) cout <<#x<<" = "<<x<<endl
#define PIar(a,n) rep(i,n)cout<<a[i]<<" ";cout<<endl;
#define PIarr(a,n,m) rep(aa,n){rep(bb, m)cout<<a[aa][bb]<<" ";cout<<endl;}
const double EPS= 1e-9 ; /* ///////////////////////// C o d i n g S p a c e ///////////////////////// */ const int MAXN= 1000 + 9 ; ll d,k,a,b,t; int main()
{
iostream::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
while(cin>>d>>k>>a>>b>>t)
{
ll ans=0;
if (d<=k)
{
cout<<min(d*a,d*b)<<endl;
continue;
}
ll mod=d%k;
ll ovmod=d/k*k;
//后面的那种情况就是,选择坐车之后不修走着
ans+=min(min(ovmod/k*t-t+ovmod*a,ovmod*b),(ovmod-k)*b+k*a);
ans+=min(t+mod*a,mod*b);
PI(ans);
}
return 0;
}

Educational Codeforces Round 15 Road to Post Office的更多相关文章

  1. Educational Codeforces Round 15_D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. Codeforces Educational Codeforces Round 15 D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. Educational Codeforces Round 15 D. Road to Post Office 数学

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. Educational Codeforces Round 15 (A - E)

    比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...

  5. Educational Codeforces Round 15 D 数学推公式

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. Codeforces Educational Codeforces Round 15 C. Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  7. Codeforces Educational Codeforces Round 15 A. Maximum Increase

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Educational Codeforces Round 15 C. Cellular Network(二分)

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  9. Educational Codeforces Round 15 C 二分

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. ExtJS常用的正则表达式

    正则表达式用于字符串处理.表单验证等场合,实用高效.现将一些常用的表达式收集于此,以备不时之需. Ext.onReady(function(){ Ext.QuickTips.init(); }); E ...

  2. Java——设计模式(单例模式)

     /* * 设计模式: 对问题行之有效的解决方式,其实他是一种思想. * 1.单例设计模式. *  解决问题:  就是可以保证一个列在内存中的对象唯一性. * *如何保证对象的唯一性: *1. 不 ...

  3. (转) SLAM系统的研究点介绍 与 Kinect视觉SLAM技术介绍

          首页 视界智尚 算法技术 每日技术 来打我呀 注册     SLAM系统的研究点介绍 本文主要谈谈SLAM中的各个研究点,为研究生们(应该是博客的多数读者吧)作一个提纲挈领的摘要.然后,我 ...

  4. Nginx安全配置研究

    x00 测试环境 ? 1 2 3 操作系统:CentOS6.5 Web服务器:Nginx1.4.6 Php版本:Php5.4.26 0x01 Nginx介绍 nginx本身不能处理PHP,它只是个we ...

  5. AssetStore资源名字

    NGUI A Pathfinding Project Pro PlayMaker 2DToolkit Scene Manager UniLOD UniLUA Save Game-JSON+Binary ...

  6. malloc(): memory corruption: 0x0000000001cc7120 ***

    今天在调试一个程序时发生如题所示的错误,在malloc时报错. 经查是由于前面有内存越界,导致内存结构遭到破坏,才发生这样的错误.

  7. 浅拷贝,深拷贝---ios

    #import <Foundation/Foundation.h> @interface Father : NSObject <NSCopying,NSMutableCopying& ...

  8. Google perf tools for nginx

    注意:本教程仅适用于Linux. 下面为大家介绍google-perftools的安装,并配置Nginx和MySQL支持google-perftools. 首先,介绍如何优化Nginx: 1,首先下载 ...

  9. python tornado框架实现CRUD

    1.本例采用postgresql数据库,创建数据表 user_tbl ),signup_date date); 2.webapi接口 (1)tornado框架配置 t_tornado.py #-*- ...

  10. 转载:使用sklearn进行数据挖掘

    目录 1 使用sklearn进行数据挖掘 1.1 数据挖掘的步骤 1.2 数据初貌 1.3 关键技术2 并行处理 2.1 整体并行处理 2.2 部分并行处理3 流水线处理4 自动化调参5 持久化6 回 ...