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

Codeforces 449A Jzzhu and Chocolate(贪心)

 
阅读更多

题目链接:Codeforces 449A Jzzhu and Chocolate

题目大意:给定一个nm的巧克力,问说切k刀之后,使得说最小的一份面积最大。

解题思路:贪心,尽量切一个方向,比较一下两种的最优解。

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

using namespace std;
typedef long long ll;
ll n, m, k;

ll gao (ll x, ll y) {
    ll a = n / (x + 1);
    a = min(a, n - a * x);
    ll b = m / (y + 1);
    b = min(b, m - b * y);
    return a * b;
}

ll solve () {
    if (n + m - 2 < k)
        return -1;
    ll x = max(k - n + 1, 0LL);
    ll y = max(k - m + 1, 0LL);
    return max(gao(k - x, x), gao(y, k - y));
}

int main () {
    scanf("%lld%lld%lld", &n, &m, &k);
    printf("%lld\n", solve());
    return 0;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics