标签: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?
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 题意:坐地铁,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