牛客第五场多校 J plan 思维

链接: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个学生要住酒店,酒店有双人房和三人房,两种房间的价格为p2,p3,问怎么住可以花费最小
分析:所有情况有五种:
    所有学生全部住双人间
    所有学生全部住三人间
    学生先住三人间,如果有剩一到两个人则去住双人间
    学生先住三人间,如果有剩四个人则去住两间双人房
    学生先住两人间,最后剩一到三人则去住三人间
计算所有情况花费的费用,取最小值
AC代码:
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define ls (r<<1)
#define rs (r<<1|1)
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
const ll maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
int main() {
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll n, p2, p3;
    while( cin >> n >> p2 >> p3 ) {
        ll ans = (n+1)/2*p2;
        ans = min( ans, (n+2)/3*p3 );
        ans = min( ans, n/3*p3+p2 );
        ans = min( ans, (n-2)/3*p3+p2+p2);
        ans = min( ans, (n-2)/2*p2+p3 );
        cout << ans << endl;
    }
    return 0;
}

  

posted on 2018-08-02 21:05  九月旧约  阅读(277)  评论(0编辑  收藏  举报

导航