Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
- each cut should be straight (horizontal or vertical);
- each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
- each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 × 6 chocolate for 5 times.
![](https://i-blog.csdnimg.cn/blog_migrate/8a0751924c9be6d859cf0716b5242722.png)
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
A single line contains three integers n, m, k (1 ≤ n, m ≤ 109; 1 ≤ k ≤ 2·109).
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
3 4 1
6
6 4 2
8
2 3 4
-1
In the first sample, Jzzhu can cut the chocolate following the picture below:
![](https://i-blog.csdnimg.cn/blog_migrate/01993b3a9ca42c005a333ba3c369086e.png)
In the second sample the optimal division looks like this:
![](https://i-blog.csdnimg.cn/blog_migrate/06d4ddbe96ada88787e3caf690fe7a88.png)
In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
题意:切巧克力,且只能完整的切一刀,不能且到中间,求切的所有块中的最小值最大的切法。
解题思路:这里求最小值最大,其实就是平均分的时候最大,就是要尽可能平均分。这里我们考虑四种情况,第一种是k(切的数)>(n+m-2),即这时候是不成立的,没有那么多边让它切,第二种情况是n>k,这时候,平均分的话,得到的值就是m*(n/(k+1))。第三种情况是m>k,这时候就是n*(m/(k+1))。还有就是n<k的情况,这时侯就是m/(k-n+2),m<k时,为n/(k-m+2).比较这四种答案,最大的那个值就是最后的答案。
AC代码:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
long long int n, m;
long long int k;
long long int ans;
int main()
{
ans = 0;
cin >> n >> m;
cin >> k;
if (k > n + m - 2) ans = -1;
else
{
if (n > k) ans = max(ans, (n / (k + 1))*m);
if (m > k) ans = max(ans, (m / (k + 1))*n);
if (n <= k) ans = max(ans, m / (k - n + 2));
if (m <= k) ans = max(ans, n / (k - m + 2));
}
cout << ans << endl;
return 0;
}