日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Jzzhu and Chocolate(CF-449A)

發布時間:2025/3/17 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Jzzhu and Chocolate(CF-449A) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Problem Description

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.

Examples

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,代表一個 n*m 的矩陣要切 k 次,問切完后最小的單元格的最大值

思路:

假設橫向切了 x-1 次,縱向切了 y-1 次,那么橫著就分為 x 份,縱著就分為 y 份

于是結果即為:res=(n/x)*(m/y),而題目所給范圍為:1<=x<=n,1<=y<=m,(x-1)+(y-1)=k

顯然:(n+m-2)<k 時無解,(n+m-2)=k 時值為 1

可以考慮先枚舉 n/x 的值,那么對于固定的取值,可以選出最大的 x,使得此時 m/y 最大;然后再枚舉? n/y?的值,那么對于固定的取值,可以選出最大的 y,使得此時 n/x?最大,最后取兩者最大值即可

我們將 y=k+2-x 代入?res=(n/x)*(m/y) 中可得到分母是一個二元函數:-y^2+2*y+ky,那么要讓原式最大,就要讓分母最小,因此不需枚舉 x、y 的值,直接令 x、y 分別最小即可

Source Program

#include<iostream> #include<cstdio> #include<cstdlib> #include<string> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<utility> #include<stack> #include<queue> #include<vector> #include<set> #include<map> #define PI acos(-1.0) #define E 1e-9 #define INF 0x3f3f3f3f #define LL long long const int MOD=1e9+7; const int N=10+5; const int dx[]= {-1,1,0,0}; const int dy[]= {0,0,-1,1}; using namespace std; int main(){int n,m,k;cin>>n>>m>>k;LL res=0;if( (n-1)+(m-1)<k )//刀數多于切口數res=-1;else if( (n-1)+(m-1)==k )//刀數等于切口數res=1;else{LL x=min(n-1,k);//令x最小res=max( res, (n/(x+1))*(m/(k+1-x)) );LL y=min(m-1,k);//令y最小res=max( res, (m/(y+1))*(n/(k+1-y)) );}cout<<res<<endl;return 0; }

?

新人創作打卡挑戰賽發博客就能抽獎!定制產品紅包拿不停!

總結

以上是生活随笔為你收集整理的Jzzhu and Chocolate(CF-449A)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。