A. Cheap Travel
来源:互联网 发布:checkpoint软件下载 编辑:程序博客网 时间:2024/05/21 06:24
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
The single line contains four space-separated integers n, m, a, b (1 ≤ n, m, a, b ≤ 1000) — the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
Print a single integer — the minimum sum in rubles that Ann will need to spend.
6 2 1 2
6
5 2 2 3
8
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
解题说明:此题是一道简单的模拟题,要么花少点钱每次买票,要么花多一点的钱买一次票用m次,简单比较即可。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<string>#include<cmath>using namespace std;int main(){int n,m,a,b,sum,med;sum=0;scanf("%d%d%d%d",&n,&m,&a,&b);if(m*a<b){med=m*a;}else{med=b;}sum=sum+(n/m)*med;n=n%m;if(n>0){if((n*a)<b){sum=sum+n*a;}else{sum=sum+b;}}printf("%d\n",sum);return 0;}
- A. Cheap Travel
- 【CODEFORCES】 A. Cheap Travel
- 466A. Cheap Travel
- Codeforces 466 A. Cheap Travel
- CodeForces 466A Cheap Travel
- CodeForces 466A Cheap Travel
- Codeforces 466A Cheap Travel(水题)
- Codeforces 466A Cheap Travel【水题】暴力
- Codeforces Round #266 (Div. 2) A. Cheap Travel
- Codeforces Round #266 (Div. 2) A. Cheap Travel
- codeforces——466A——Cheap Travel
- cf466A Cheap Travel
- Codeforces Cheap Travel
- Cheap Travel(暴力求解法)
- CodeForces 55A. Flea travel
- CodeForces 75A Flea travel
- Travel
- Travel
- SDUTOJ 2135--数据结构实验之队列一:排队买饭
- Query的时效性挖掘
- 走进SylixOS代码
- codeforces round #266 C. Number of Ways
- JabRef 入门
- A. Cheap Travel
- CentOS配置VSFTP服务器
- C++ 中const关键字小记
- 数据结构概括
- Apache开启deflate(Gzip)和Expires提升网页加载速度
- 自定义标签实现分页简单化
- 1024!末尾有几个零?
- BZOJ 1269 [AHOI2006]文本编辑器editor Splay伸展树
- UVa11105 - Semi-prime H-numbers(sieve的思想)