codeforce 702D Road to Post Office 物理计算路程题

http://codeforces.com/contest/702

题意:人到邮局去,距离d,汽车在出故障前能跑k,汽车1公里耗时a,人每公里耗时b,修理汽车时间t,问到达终点最短时间

思路:计算车和人的平均速度,谁快用谁,最后特判<=k的距离

 1 // #pragma comment(linker, "/STACK:102c000000,102c000000")
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <sstream>
 6 #include <string>
 7 #include <algorithm>
 8 #include <list>
 9 #include <map>
10 #include <vector>
11 #include <queue>
12 #include <stack>
13 #include <cmath>
14 #include <cstdlib>
15 // #include <conio.h>
16 using namespace std;
17 #define pi acos(-1.0)
18 const int N = 1e5+10;
19 const int MOD = 1e9+7;
20 #define inf 0x7fffffff
21 typedef long long  LL;
22 
23 void frein(){freopen("in.txt","r",stdin);}
24 void freout(){freopen("out.txt","w",stdout);}
25 inline int read(){int x=0,f=1;char ch=getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;}
26 
27 int a[N];
28 int b[N];
29 
30 int main(){
31     LL d,k,a,b,t;
32     cin>>d>>k>>a>>b>>t;   
33     if((d-d%k)<=0){
34         printf("%I64d\n",a*d);
35         exit(0);
36     }
37     LL ans1,ans2;
38     if((double)(1.0*(k*a+t)/k)<b){
39         ans1=(d-d%k)*a+(d/k-1)*t;
40         d-=d/k*k;
41         ans2=min(a*d+t,b*d);
42     }
43     else {
44         ans1=(d-k)*b;
45         ans2=k*min(a,b);
46     }
47     printf("%I64d\n",ans1+ans2);
48     return 0;
49 }

 

posted @ 2016-08-02 11:23  yyblues  阅读(279)  评论(0)    收藏  举报