Codeforces 450C:Jzzhu and Chocolate(贪心)

C. Jzzhu and Chocolate

time limit per test: 1 secondsios

memory limit per test: 256 megabytesc++

input: standard inputide

output: standard outputui

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

  • 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.spa

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.3d

Input

A single line contains three integers \(n, m, k (1 ≤ *n*, *m* ≤ 10^9; 1 ≤ k ≤ 2·10^9)\).code

Output

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

inputthree

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\times m\)大小的巧克力,巧克力有\(n\times m\)个格子,要求切\(k\)刀以后,使切得的最小的方块面积最大,求这个最小的面积

思路

贪心

每次切的时候先尽量的朝着一个方向切,切完以后在考虑另外那个方向,切得时候注意要平均切。而后比较首先横向切和首先纵向切的最大值

注意当\(k>n+m-2\)的状况是没法切的

代码

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ms(a,b) memset(a,b,sizeof(a))
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=1e6+10;
const int mod=1e9+7;
const int maxm=1e3+10;
using namespace std;
ll solve(ll n,ll m,ll k)
{
    if(n>k)
        return n/(k+1)*m;
    k-=(n-1);
    return m/(k+1);
}
int main(int argc, char const *argv[])
{
    #ifndef ONLINE_JUDGE
        freopen("/home/wzy/in", "r", stdin);
        freopen("/home/wzy/out", "w", stdout);
        srand((unsigned int)time(NULL));
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m,k;
    cin>>n>>m>>k;
    if(k>n+m-2)
        cout<<-1<<endl;
    else
        cout<<max(solve(n, m, k),solve(m,n,k));
    #ifndef ONLINE_JUDGE
        cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
    #endif
    return 0;
}
相关文章
相关标签/搜索