链接: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个人住宾馆,二人房价钱p2,三人房价钱p3 。求这n个人全部住进宾馆的最少花费

思路

暴力进行判断

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

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

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

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#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<<min(p2,p3)<<endl;
continue;
}
if(flag1==0&&flag2==0)
ans=min(n/2*p2,n/3*p3);
else if(flag1==0&&flag2)
{
ll x=n/3;
if(flag2==2)
ans=min(n/2*p2,min(x*p3+p2,min((x-1)*p3+3*p2,(x+1)*p3)));
if(flag2==1)
ans=min(n/2*p2,min(x*p3+p2,min((x+1)*p3,min(p2*(n/2-1)+p3,p3*(x-1)+p2*2))));
}
else if(flag1&&flag2==0)
{
ll y=n/2;
ans=min((y+1)*p2,min(n/3*p3,(y-1)*p2+p3));
}
else if(flag1&&flag2)
{
ll x=n/2;
ll y=n/3;
if(flag2==1)
ans=min((x+1)*p2,min((y+1)*p3,min((y-1)*p3+2*p2,min(p2*(x-1)+p3,y*p3+p2))));
else if(flag2==2)
ans=min((x+1)*p2,min((y+1)*p3,min(y*p3+p2,min((x-1)*p2+p3,(y-1)*p3+3*p2))));
}
cout<<ans<<endl;
}
return 0;
}

牛客多校第五场 J:Plan的更多相关文章

  1. 牛客多校第3场 J 思维+树状数组+二分

    牛客多校第3场 J 思维+树状数组+二分 传送门:https://ac.nowcoder.com/acm/contest/883/J 题意: 给你q个询问,和一个队列容量f 询问有两种操作: 0.访问 ...

  2. 牛客多校第六场 J Heritage of skywalkert 随即互质概率 nth_element(求最大多少项模板)

    链接:https://www.nowcoder.com/acm/contest/144/J来源:牛客网 skywalkert, the new legend of Beihang University ...

  3. 牛客多校第五场 E room 二分图匹配 KM算法模板

    链接:https://www.nowcoder.com/acm/contest/143/E来源:牛客网 Nowcoder University has 4n students and n dormit ...

  4. 牛客多校第五场 F take

    链接:https://www.nowcoder.com/acm/contest/143/F来源:牛客网 题目描述 Kanade has n boxes , the i-th box has p[i] ...

  5. 牛客多校第五场-D-inv

    链接:https://www.nowcoder.com/acm/contest/143/D来源:牛客网 题目描述 Kanade has an even number n and a permutati ...

  6. 牛客多校第五场 F take 期望转化成单独事件概率(模板) 树状数组

    链接:https://www.nowcoder.com/acm/contest/143/F来源:牛客网 Kanade has n boxes , the i-th box has p[i] proba ...

  7. 字符串dp——牛客多校第五场G

    比赛的时候脑瘫了没想出来..打多校以来最自闭的一场 显然从s中选择大于m个数组成的数必然比t大,所以只要dp求出从s中选择m个数大于t的方案数 官方题解是反着往前推,想了下反着推的确简单,因为高位的数 ...

  8. 【魔改】树状数组 牛客多校第五场I vcd 几何+阅读理解

    https://www.nowcoder.com/acm/contest/143/I vc-dimension 题解:分三种情况,组合数学算一下,其中一种要用树状数组维护 技巧(来自UESTC):1. ...

  9. 牛客多校第四场 J.Hash Function(线段树优化建图+拓扑排序)

    题目传送门:https://www.nowcoder.com/acm/contest/142/J 题意:给一个hash table,求出字典序最小的插入序列,或者判断不合法. 分析: eg.对于序列{ ...

随机推荐

  1. js插件---在线类似excel生成图表插件解决方案

    js插件---在线类似excel生成图表插件解决方案 一.总结 一句话总结:google比百度好用多了,多用google google js editable table jquery 双向绑定 这种 ...

  2. codeforces 484b//Maximum Value// Codeforces Round #276(Div. 1)

    题意:给一个数组,求其中任取2个元素,大的模小的结果最大值. 一个数x,它的倍数-1(即kx-1),模x的值是最大的,然后kx-2,kx-3模x递减.那么lower_bound(kx)的前一个就是最优 ...

  3. 52 53django

    一.需要弄清楚的几个关键点: KEY: 1 Django项目无论多大,只是一个应用程序 2 地址栏发请求默认是GET请求 form表单可以发送get请求,也可以发送post请求 3 浏览器接受的响应体 ...

  4. 数据库,ADO.NET(ADO),Oledb(Odbc)和编程语言关系框架图

    ---恢复内容开始--- ---恢复内容结束---

  5. 查询(sqlSuger)

    查某一天的数据记录的条数 DateTime date1 = Convert.ToDateTime(DateTime.Now.ToShortDateString()); DateTime date2 = ...

  6. bind出现Address already in use解决方法

    在socket函数和bind函数之间加入一段代码: // 建立服务器端socket if((server_sockfd = socket(AF_INET, SOCK_STREAM, 0))<0) ...

  7. UVALive 5984

    题目链接:Save the Students! #include<stdio.h> #include<string.h> #include<iostream> #i ...

  8. Python3.5+SQL+Prometheus+Grafana报表/监控

    参考资料: pymysql 单独获取表的栏位名称 pymysql返回数据为字典形式(key:value--列:值)   行列结合,作为prometheus_client的输出. 话不多说,直接上脚本. ...

  9. DevExpress v17.2新版亮点——VCL篇(一)

    用户界面套包DevExpress v17.2日前终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress VCL v17.2 的新功能,快来下载试用新版本! 全新的U ...

  10. 【DevExpress v17.2新功能预告】增强ASP.NET GridView的功能

    在下一个主要版本v17.2中,我们将为DevExpress ASP.NET GridView添加一些优秀的新功能.在本文中为大家介绍的所有功能都可用于 GridView的ASP.NET WebForm ...