zoukankan      html  css  js  c++  java
  • [CF466B] Wonder Room

    [CF466B] Wonder Room

    Description

    每一间宿舍有一个a*b平方米的房间,想在那里正好容纳N个学生,每个学生的房间必须至少有6平方米,可以将房间的任何一侧(可能是两侧)扩大任意正整数米。扩建房间,使n个学生都能住在里面,且使房间的总面积尽可能小。

    Solution

    考虑枚举短边,这样实际上只要枚举到根号的位置就可以了

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    
    signed main()
    {
        ios::sync_with_stdio(false);
    
        int n, a, b;
        cin >> n >> a >> b;
        n *= 6;
    
        int ans = 2e18, ans_a, ans_b;
        int swap_flag = a > b;
        if (a > b)
            swap(a, b);
    
        for (int i = 1; i * i <= 2 * n; i++)
        {
            int x = i;
            int y = (n + i - 1) / i;
            x = max(a, x);
            y = max(b, y);
            if (x * y < ans)
            {
                ans = x * y;
                ans_a = x;
                ans_b = y;
            }
        }
    
        if (swap_flag)
            swap(ans_a, ans_b);
        cout << ans << endl
             << ans_a << " " << ans_b;
    }
    
  • 相关阅读:
    HDU 1985 Conversions
    HDU 1708 Fibonacci String
    HDU 3501 Calculation 2
    HDU 4163 Stock Prices
    HDU 2391 Filthy Rich
    HDU 1996 汉诺塔VI
    HDU 2824 The Euler function
    HDU 1787 GCD Again
    HDU 2393 Higher Math
    HDU 1286 找新朋友
  • 原文地址:https://www.cnblogs.com/mollnn/p/14449348.html
Copyright © 2011-2022 走看看