链接:https://www.nowcoder.com/acm/contest/143/J
来源:牛客网
plan
时间限制: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个人两人间的房子的价格p2,三人间房子的价格p3,问怎么安排人花费最小。
分析:按性价比贪心,肯定让更多的人住性价比高的。
#include <bits/stdc++.h>
using namespace std;
int main()
{
double aa,bb;
long long n,i,j,m,p,q;
long long sum;
scanf("%lld%lld%lld",&n,&p,&q);
aa=p*1.0/2;
bb=q*1.0/3;
sum=0;
if(aa>bb)
{
bool flag;
flag=n%3;
sum=min(p,q)*flag+n/3*q;
// printf("%lld\n",sum);
if(n%3==1)
sum=min(sum,(n/3-1)*q+2*min(p,q));//三人间拿出人来,和多余一人变两人间
}
else
{
bool flag;
flag=n%2;
sum=min(p,q)*flag+n/2*p;
if(n%2)
sum=min(sum,(n/2-1)*p+q);//两人间拿出人来和剩余的人去三人间
}
printf("%lld\n",sum);
}