`
阿尔萨斯
  • 浏览: 4185115 次
社区版块
存档分类
最新评论

Codeforces 466B Wonder Room(暴力)

 
阅读更多

题目链接:Codeforces 466B Wonder Room

题目大意:给定n,a,b,要求找到ai,bi,(ai≥a, bi≥b)并且aibi6n,并且aibi要尽量小。

解题思路:枚举ai,根据6n算出需要的bi,注意ai只需要枚举到
6n




#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int main () {
    bool flag = false;
    ll n, a, b, ans = INF, l, r;

    scanf("%lld%lld%lld", &n, &a, &b);
    n *= 6;

    if (a > b) {
        swap(a, b);
        flag = true;
    }

    for (ll i = 1; i <= n; i++) {
        ll x = i, y = (n - 1) / i + 1;
        if (x > y)
            break;
        x = max(x, a);
        y = max(y, b);
        if (x * y < ans) {
            ans = x * y;
            l = x;
            r = y;
        }
    }

    if (flag)
        swap(l, r);

    printf("%lld\n%lld %lld\n", ans, l, r);
    return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics