链接: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. Codeforces 580A - Kefa and First Steps

    580A - Kefa and First Steps 思路:dp dp[i]表示包括前i个元素中a[i]在内的最大增序列. 代码: #include<bits/stdc++.h> usi ...

  2. Html概述

    Html概述 主要思想,主要思想很重要 一.Html是什么 一种标记语言(用标签进行标记) 对要显示的文字进行标记 二.Html核心 标签(只认标签) 封装,所以必须有头尾,你才知道标签的范围,你才知 ...

  3. VMware 怎么判断哪台机子试图用混杂模式且不成功

    主要是看个log, 然后推断虚拟端口号 The VMkernel logs at /var/log/vmkernel or /var/log/messages contain entries simi ...

  4. 使用MyBatis Generator自动生成实体、mapper和dao层

    原文链接 通过MyBatis Generator可以自动生成实体.mapper和dao层,记录一下怎么用的. 主要步骤: 关于mybatis从数据库反向生成实体.DAO.mapper: 参考文章:ht ...

  5. php7-soap调用wsdl接口报错:Could not connect to host

    由php5.6升级到php7.1以上版本,在用soap调用wsdl接口是报错:Could not connect to host 后来经过排查是centos服务器上装有2个版本的openssl造成的. ...

  6. [.NET开发] 浅说C#异步和同步

    提到异步,那么与之对应的是什么呢?同步.那么C#的异步和同步是如何工作的呢? 首先,我们先来看看栗子: 新建一个控制台应用程序,在Program文件中添加如下代码: 1 static void Mai ...

  7. 20170624xlVBA正则分割分类汇总

    Sub RegExpSubtotal() '声明变量 Dim Regex As Object '正则对象 Dim Dic As Object '字典对象 Dim Key As String '关键字 ...

  8. Lightoj Halloween Costumes

    题意:给出要n个时间穿的服装.服装脱下就不能再穿.问最少要准备多少? dp[i][j]表示i到j之间最少花费.如果n=1(n指长度),肯定结果为1,n=2时,也很好算.然后n=3的时候dp[i][j] ...

  9. Pandas DataFrame 数据选取和过滤

    This would allow chaining operations like: pd.read_csv('imdb.txt') .sort(columns='year') .filter(lam ...

  10. SSO-基本概念

    什么是单点登录 单点登录(Single Sign On) 简称为sso,是目前流行的企业业务整合的解决方案之一.SSO的定义是在多个引用系统中用户只需要登录一次就可以访问所有相互信任的应用系统. 单点 ...