C. jzzhu and chocolatetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Jzzhu has a big rectangular chocolate bar that consistsN? ×?MUnit squares. He wants to cut this bar exactlyKTimes. Each cut must meet the following requirements:
- Each cut shoshould be straight (horizontal or vertical );
- Each cut shoshould go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut );
- Each cut shoshould 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 madeKCuts 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 exactlyKCuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three IntegersN,?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 chocolateKTimes, 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.
Question
Funny question. Is a grid-like item, N rows of M columns, straight cut K knife, ask all the possibilities, the biggest, each cut out the smallest block size of the result.
I was so greedy that I had to kneel down. After the game, we found that we could enumerate the number of possible switches in this direction, calculate the number of switches in the column direction, and then update the answer method. Of course, only the enumeration factor is used for enumeration, so that the complexity can be reduced from O (n) to O (SQRT (n )). Some optimization is added in the middle, and then it will be okay.
Sample Code
/*************************************** **************************************** Copyright Notice * copyright (c) 2014 All Rights Reserved * ---- stay hungry Stay Foolish ---- ** @ Author: Shen * @ name: C * @ file: G: \ My source code \ [ACM] competition \ 0719-CF \ c. CPP * @ Date: 2014/07/19 20:57 * @ algorithm: greedy *************************************** ***************************************/ # include <bits/stdc ++. h> using N Amespace STD; Template <class T> inline bool updatemin (T & A, t B) {return A> B? A = B, 1: 0;} template <class T> inline bool updatemax (T & A, t B) {return a <B? A = B, 1: 0;} typedef long int64; int64 n, m, K, ans; int64 run () {If (n-1 + m-1 <K) ans =-1; for (int64 I = 1; I <= N; I ++) {int64 r = N/(n/I); I = R; if (k-(R-1)> m-1) continue; int64 o = max (k-(R-1) + 1, 1ll); updatemax (ANS, 1ll * (N/R) * (M/O);} return ans;} int main () {CIN> N> m> K; cout <run () <Endl; return 0 ;}
Codeforces round #257 (Div. 2) C greedy