牛客多校第五场 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

牛客多校第五场 J:Plan_第1张图片

题意

n个人住宾馆,二人房价钱p2,三人房价钱p3 。求这n个人全部住进宾馆的最少花费

思路

暴力进行判断

先对1个人进行特判:最少的花费肯定是min(p2,p3)。

然后因为二人房和三人房有一定的性价比(即平均每个人的住房花费)。所以入住的时候肯定要尽可能多的选择性价比高的房间(平均每人花费最少),所以可以选择:全部是二人间,全部是三人间,如果有剩余,让剩下的人住二人间或三人间,对于所有的情况取最小值就是最小花费。

大概就是这样,代码里写的有点麻烦,好像有些情况用不到,这样写情况容易考虑不全,WA了15次之后才把所有的情况写全。不知道大佬们都是怎么写的。如果有更好的思路,欢迎交流٩(๑>◡<๑)۶ 

AC代码

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define ll unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
const double E=exp(1);
const int maxn=1e6+10;
using namespace std;
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	ll n,p2,p3;
	ll ans=0;
	ll flag1=0,flag2=0;
	while(cin>>n>>p2>>p3)
	{
		flag1=n%2;
		flag2=n%3;
		if(n==1)
		{
			cout<

 

转载于:https://www.cnblogs.com/Friends-A/p/10324423.html

你可能感兴趣的:(牛客多校第五场 J:Plan)