1. 程式人生 > >牛客多校第五次-J題-plan

牛客多校第五次-J題-plan

連結:https://www.nowcoder.com/acm/contest/143/J
來源:牛客網
 

時間限制:C/C++ 1秒,其他語言2秒
空間限制:C/C++ 262144K,其他語言524288K
64bit IO Format: %lld

題目描述

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.

示例1

輸入

複製

4 2 3

輸出

複製

4

示例2

輸入

複製

5 1 3

輸出

複製

3

備註:

1<=n<=10^9

1<=p2,p3<=10^9

 

題目描述
n 個人出去玩,給定雙人房和三人房的價格,求最少的住宿花費
1<=n<=10^9

解題思路
腦補一下可以發現:最後答案一定是幾乎全選價效比最高的那種房間
然後再加上幾間其他的
所以二人間和三人間裡數量用的最少的房間不會超過 3
列舉一下用了幾間就好了

 

一開始,列舉的剩餘人,題解列舉最少的那個房間,很NB

int main() {
	int n, p2, p3;
	cin >> n >> p2 >> p3;
	LL ans = 1LL << 60;
	//+2是多的人也需要一個房間,max的作用是,防止剩餘人數出現負數情況
	for (int i = 0; i < 5; i++)ans = min(ans, 1LL * p2*i + 1LL * max(0, (n - i * 2 + 2) / 3)*p3);
	for (int i = 0; i < 5; ++i)ans = min(ans, 1LL * p3*i + 1LL * max(0, (n - i * 3 + 1) / 2)*p2);
	cout << ans << endl;
}