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;
}
相關文章
相關標籤/搜索