2018牛客多校05 J plan(数学,规律)

链接:https://www.nowcoder.com/acm/contest/143/J

n个人住宾馆,双人间价格为p2,三人间价格为p3,如何安排,使总花费最少。

列方程,枚举最近的6个结果即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;

using LL = long long;
LL n, a, b;

signed main() {
// freopen("in", "r", stdin);
while(~scanf("%lld%lld%lld",&n,&a,&b)) {
LL ret = 1e18;
for(LL i = 0; i <= 6; i++) {
ret = min(ret, (n+1-i)/2*a+(i+2)/3*b);
ret = min(ret, (n+2-i)/3*b+(i+1)/2*a);
}
printf("%lld\n", ret);
}
return 0;
}