标签:bsp price 全局 www can http def nim 情况
题目链接:https://www.nowcoder.com/acm/contest/143/J
There are n students going to travel. And hotel has two types room:double room and triple room. The price of a double room is p2 and the price of a triple room is p3
Now you need to calulate the minimum total cost of these students.
The first line has three integers n, p2, p3
Output the minimum total cost.
4 2 3
4
5 1 3
3
1<=n<=10^9
1<=p2,p3<=10^9
n 个人出去玩,给定双人房和三人房的价格,求最少的住宿花费
1<=n<=10^9
脑补一下可以发现:最后答案一定是几乎全选性价比最高的那种房间
然后再加上几间其他的
所以二人间和三人间里数量用的最少的房间不会超过 3
枚举一下用了几间就好了
因为从全局来看我们要多选性价比高的房间, 所以模拟一下分为两种大情况,而每种小情况的最后可能刚刚好住满,可能有剩余,如果双人房性价比高,那么最后有可能会剩下一个可怜的家伙,那时我们要考虑单个住便宜或是跟前面的合住三人房便宜了;如果三人房性价比高,那么最后可能剩下一个人,可能剩下两个人,综上所述,数量用的最少的房间不超过3.
AC code:
1 #include <bits/stdc++.h> 2 #define INF 0x3f3f3f3f 3 #define ll long long int 4 using namespace std; 5 6 ll N, p2, p3, u; 7 8 int main() 9 { 10 scanf("%lld%lld%lld", &N, &p2, &p3); 11 double xj_1 = p2/2.0; 12 double xj_2 = p3/3.0; 13 long long int ans = 0; 14 if(xj_1 <= xj_2) 15 { 16 if(N%2) 17 { 18 ans = (N/2-1)*p2 + min(p2*2, p3); 19 } 20 else ans = (N/2)*p2; 21 } 22 else 23 { 24 if(N%3 == 1) 25 { 26 ans = (N/3-1)*p3 + min(p2*2, p3*2); 27 } 28 else if(N%3 == 2) 29 { 30 ans = (N/3-1)*p3 + min(p2+p3, p3*2); 31 } 32 else 33 { 34 ans = N/3*p3; 35 } 36 } 37 printf("%lld\n", ans); 38 return 0; 39 }
标签:bsp price 全局 www can http def nim 情况
原文地址:https://www.cnblogs.com/ymzjj/p/9424908.html