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.

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 exactlyk 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:

In the second sample the optimal division looks like this:

In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times.
//AC代码
/*
此题题意我都理解了了半个多小时
大概题意就是:给你一个n*m的巧克力,然后切k刀,问你切完之后得到最小面积的那块最多有多少个
例如:12 10 2(10*10的巧克力,切2刀,那么怎么切呢,既然要得到最小面积的那块最多有多少个,所以我们要得到最多肯定只能认准一边切不能这边切一下那边切一下,只有这边实在切不下才去切另一边)
还有选的那一边一定是最大的,因为这样得到的最小面积才最多块(1*1)
所以我们切12这边的,那么切2刀最后肯定分成(2+1)块,所以最多的是((12/(2+1))*10)==40
但是如果两边都小于k怎么办,例如 4 5 6这样我们还是选最长的那边(即5)先切(5-1)刀【这样这边已经是切了最多不能在切下去了】
那么还剩(k-(n-1))即(6-(5-1))=2刀了,那么这两刀全切在另一边(即长为4这边),那么两刀过后切成(2+1)=3份,那么最小面积就是1*(4/3)=1了
*/
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int main()
{
long long n,m,k,x,y,z,t;
cin>>n>>m>>k;
x=n;
y=m;
z=k;
if((n+m-2)<k)
cout<<-1<<endl;
else
{
x=n;
y=m;
z=k;
t=0;
if(x<y)
{
t=x;
x=y;
y=t;
}
if(z==1)
{
if(x%2==0)
{
x/=2;
}
else
{
if(y%2==0)
y/=2;
else
{
x-=1;
}
}
cout<<x*y<<endl;
}
else
{
if((x*y)%(z+1)==0)
{
cout<<(x*y)/(z+1)<<endl;
}
else
{
if(x>z)
{
if(x>z&&y<z)
cout<<(x/(z+1))*y<<endl;
if(x>z&&y>=z)
cout<<max((x/(z+1))*y,(y/(z+1))*x)<<endl;
}
else
{
if(y>z)
{
cout<<(y/(z+1))*x<<endl;
}
else
{
if(x<z&&y<z)
{
cout<<max(x/((z-y+1)+1),y/((z-x+1)+1))<<endl;
}
else
{
if(x==z)
{
cout<<y/2<<endl;
}
else if(y==z)
{
cout<<x/2<<endl;
}
else if(x==z&&y==z)
{
cout<<x/2<<endl;
}
}
}
}
}
}
}
return 0;
}

探讨如何通过k次切割获得n×m巧克力的最大最小面积,解析切割策略及实现过程。
379

被折叠的 条评论
为什么被折叠?



