Codeforces Div. 2 #257-C. Jzzhu and Chocolate

探讨如何通过k次切割获得n×m巧克力的最大最小面积,解析切割策略及实现过程。
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 exactlyk 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.

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


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值