首页 > 代码库 > Codeforces Round #266 (Div. 2) A. Cheap Travel
Codeforces Round #266 (Div. 2) A. Cheap Travel
Ann has recently started commuting by subway. We know that a one ride subway ticket costsa rubles. Besides, Ann found out that she can buy a special ticket form rides (she can buy it several times). It costsb rubles. Ann did the math; she will need to use subwayn times. Help Ann, tell her what is the minimum sum of money she will have to spend to maken 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 them ride ticket, the price of a one ride ticket and the price of anm 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