Codeforces Round #257 C.Jzzhu and Chocolate

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值