您的位置:首页 > 其它

Codeforces Round #257 C.Jzzhu and Chocolate

2014-07-21 14:15 183 查看
C. Jzzhu and Chocolate

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

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 exactly k cuts? The
area of a chocolate piece is the number of unit squares in it.

Input

A single line contains three integers n, m, k (1 ≤ n, m ≤ 109; 1 ≤ k ≤ 2·109).

Output

Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.

Sample test(s)

input
3 4 1


output
6


input
6 4 2


output
8


input
2 3 4


output
-1


Note

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.

题目大意:

给你一块n*m的巧克力,要求切k刀,现在要求出切k刀后,使巧克力最小的一块最大,求这个值

题目分析:

n*m的矩形巧克力,min和max表示n和m中的小值和大值,则存在三种情况,

1.k<min 切小边或者切大边

2.min<k<max 切小边后切大边 或者 切大边

3.k>max 切小边后切大边 或者 切大边后切小边

4.k>min+max-2 无解

之前为什么写错是因为情况分的有问题,导致除了0,然后RE了,算是个贪心。

#include<cstring>
#include<string>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cctype>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<ctime>
#include<cstdlib>
#include<functional>
#include<cmath>
#define PI acos(-1.0)
#define MAXN 100005
#define eps 1e-7
#define INF 0x7FFFFFFF
#define ff sqrt(5.0)
using namespace std;
int main ()
{
   long long  n,m,k;
   long long  min,max;
   long long sum1=0,sum2=0,sum3=0,sum4=0;
   cin>>n>>m>>k;

   sum1=sum2=sum3=0;
   if(n<m) {min=n;max=m;}
   else {min=m;max=n;}

   if(k>(n+m-2)) {cout<<"-1"<<endl;return 0;}
   else if(k<=min-1)
   {
        sum1=max/(k+1) * min;
        sum2=min/(k+1) * max;
       if(sum1<sum2) sum1=sum2;
   }
   else if(k>=min-1&&k<=max-1)
   {
       sum3=min/(min-1+1) * (max/(k-(min-1)+1));
       sum4=max/(k+1) * min;
       if(sum4>sum3) sum3=sum4;
       if(sum3>sum1) sum1=sum3;
   }
   else if(k>=max-1)
   {
       sum3=min/(min-1+1) * (max/(k-(min-1)+1));
       sum4=max/(max-1+1) * (min/(k-(max-1)+1));
       if(sum4>sum3) sum3=sum4;
       if(sum3>sum1) sum1=sum3;
   }
   cout<<sum1<<endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: