zoukankan      html  css  js  c++  java
  • 2050第三题-分宿舍(HDU

    “那天TA说TA要来,于是我就来啦。
    那天我说我要来,于是你就来啦。
    TA看到了什么?
    你又看到了什么?
    我看到你们在一起,我是真的很happy:)
    太阳在哪里啊?
    就在早上七八点。
    太阳在哪里啊?
    就在云的栖息地!”
    ——2050主题曲


    2050的线下活动吸引了很多心怀梦想的年轻人。

    小伙们打算组团去参加。他们一共有 n+m+2kn+m+2k 个人,包括 n+kn+k 个男生,m+km+k 个女生,其中 kk 对男女生为异性情侣,现在他们要找房间住。房间有三种类型,双人间 aa 元一间,三人间 bb 元一间,这两种只能同性一起住。情侣间能住一对异性情侣,一间 cc 元。除了情侣间以外,其他房间都可以不住满。

    求最少花多少钱,能让小伙伴们都有地方住。

    Input第一行一个整数 T (1T50)T (1≤T≤50) 表示数据组数。

    接下来 TT 组数据,每组数据一行 66 个整数 n,m,k,a,b,cn,m,k,a,b,c,其中 0n,m,k103,0a,b,c1090≤n,m,k≤103,0≤a,b,c≤109。
    Output对于每组数据输出一行一个数,表示所有人住下来所需要的最小花费。Sample Input

    2
    3 0 1 1 3 3
    3 3 2 1 6 2

    Sample Output

    3
    6
    思路:这道题数据范围比较小,可以用暴力解决。根据a和b的价格,谁便宜选谁。枚举同性的住房情况,一个一个的减去情侣狗(酸),最后的价格谁便宜就选谁。
    #include <cstdio>
    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <vector>
    using namespace std;
    
    #define ll long long
    
    int t, n, m, k;
    ll a, b, c, sum;
    
    ll check(int x)
    {
        if(a*1.0/2>b*1.0/3)
        {
            if(x%3 == 0)return b*(x/3);//如果人数刚好为3的倍数
            else if(x%3 == 1)return b*(x/3)+min(b, min(a, 2*a-b));//如果还剩一个人出来,到底是住三人房便宜,还是住双人房便宜,还是把三个人拖出来一起住两间双人房便宜
            else if(x%3 == 2)return b*(x/3)+min(b, a);//如果还剩一个人,是住三人房便宜,还是住双人房便宜
        }
        else
        {
            if(x%2 == 0)return a*(x/2);//如果一个也不剩
            return a*(x/2)+min(a, b-a);//如果还剩一个,是住双人房,还是拖两个人出来住三人房
        }
    }
    
    int main()
    {
        scanf("%d", &t);
        while(t--)
        {
            sum = 0x3f3f3f3f3f3f3f3f;
            scanf("%d%d%d%lld%lld%lld", &n, &m, &k, &a, &b, &c);
            for(int i = 0; i <= k; i++)
            {
                sum = min(sum, check(n+k-i)+check(m+k-i)+i*c);
            }
            printf("%lld
    ", sum);
        }
        return 0;
    }
  • 相关阅读:
    LeetCode "Median of Two Sorted Arrays"
    LeetCode "Distinct Subsequences"
    LeetCode "Permutation Sequence"

    LeetCode "Linked List Cycle II"
    LeetCode "Best Time to Buy and Sell Stock III"
    LeetCode "4Sum"
    LeetCode "3Sum closest"
    LeetCode "3Sum"
    LeetCode "Container With Most Water"
  • 原文地址:https://www.cnblogs.com/RootVount/p/10939751.html
Copyright © 2011-2022 走看看