码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #266 (Div. 2) A. Cheap Travel

时间:2014-09-15 10:05:28      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:des   io   os   ar   for   art   div   sp   cti   

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?

Input

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.

Output

Print a single integer — the minimum sum in rubles that Ann will need to spend.

Sample test(s)
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
题意:坐地铁,1个站需要a元,m个站需要b元,求走n个站需要的最小的钱
思路:n不大,所以我们直接枚举坐一个站的个数,剩下的坐m个站的
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int inf = 0x3f3f3f3f;

int main() {
	int n, m, a, b;
	scanf("%d%d%d%d", &n, &m, &a, &b);

	int ans = inf;
	for (int i = 0; i <= n; i++) {
		int numM = (n - i + m - 1) / m;
		int cur = a * i + numM * b;
		if (cur < ans)
			ans = cur;
	}
	printf("%d\n", ans);
	return 0;
}


Codeforces Round #266 (Div. 2) A. Cheap Travel

标签:des   io   os   ar   for   art   div   sp   cti   

原文地址:http://blog.csdn.net/u011345136/article/details/39288799

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!