本文主要是介绍Codeforces 466B Wonder Room(暴力),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:Codeforces 466B Wonder Room
题目大意:给定n,a,b,要求找到ai,bi,(ai≥a, bi≥b)并且ai∗bi≥6∗n,并且ai∗bi要尽量小。
解题思路:枚举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;
}
这篇关于Codeforces 466B Wonder Room(暴力)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!