题目链接: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.
示例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
枚举一下用了几间就好了

大概思路:

因为从全局来看我们要多选性价比高的房间, 所以模拟一下分为两种大情况,而每种小情况的最后可能刚刚好住满,可能有剩余,如果双人房性价比高,那么最后有可能会剩下一个可怜的家伙,那时我们要考虑单个住便宜或是跟前面的合住三人房便宜了;如果三人房性价比高,那么最后可能剩下一个人,可能剩下两个人,综上所述,数量用的最少的房间不超过3.

AC code:

 #include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll long long int
using namespace std; ll N, p2, p3, u; int main()
{
scanf("%lld%lld%lld", &N, &p2, &p3);
double xj_1 = p2/2.0;
double xj_2 = p3/3.0;
long long int ans = ;
if(xj_1 <= xj_2)
{
if(N%)
{
ans = (N/-)*p2 + min(p2*, p3);
}
else ans = (N/)*p2;
}
else
{
if(N% == )
{
ans = (N/-)*p3 + min(p2*, p3*);
}
else if(N% == )
{
ans = (N/-)*p3 + min(p2+p3, p3*);
}
else
{
ans = N/*p3;
}
}
printf("%lld\n", ans);
return ;
}

最新文章

  1. python之网络编程
  2. 为 WSUS 服务器定期运行清理向导
  3. Delphi的Win32的API调用简单介绍
  4. HTTP请求中的form data和request payload的区别
  5. IOS开发之——Masonry 只支持OC,暂不支持swift
  6. Drupal 7.31版本爆严重SQL注入漏洞
  7. IT码农哥放弃50万年薪:辞职卖咖喱凉皮(背后深藏功与名)_互联网的一些事
  8. CharacterEncodingFilter -处理字符格式
  9. 【JAVASCRIPT】React + Redux
  10. Linux入门(6)——Ubuntu16.04安装atom
  11. .Net Core 中间件之主机地址过滤(HostFiltering)源码解析
  12. Haskell语言学习笔记(87)Time
  13. Pascal&#39;s Triangle II Leetcode java
  14. 使用PHP-GTK编写一个windows桌面应用程序
  15. Java的工厂模式(二)
  16. Facebook数据库工具Flashcache初探
  17. Bash Shell中Shift用法分享
  18. 下载Web微信视频
  19. css滤镜让图片模糊
  20. UVa 10562 Undraw the Trees 看图写树

热门文章

  1. oracle sql命令
  2. java多态的具体表现实例和理解
  3. adb调试安卓
  4. elasticsearch 2.4.0执行update的时候发现的一个问题
  5. 《腾讯游戏人生》微信小程序开发总结
  6. CF 303C——Minimum Modular——————【剪枝】
  7. CF 304B——Calendar——————【年月日计算】
  8. AtCoder Grand Contest 023 E - Inversions
  9. Dictionary集合 字典
  10. 类的方法练习——定义MySQL类