codeforces C. Jzzhu and Chocolate

http://codeforces.com/contest/450/problem/C

题意:一个n×m的矩形,然后可以通过横着切竖着切,求切完k次之后最小矩形面积的最大值。

思路:设k1为横着切的次数,k2为竖着切的次数,最后的面积的大小为s=n/(k1+1)*(m/(k2+1)); 只有(k1+1)*(k2+1)的最小时,s最大.

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <algorithm>
 5 #define ll long long
 6 using namespace std;
 7 
 8 ll n,m,k;
 9 
10 int main()
11 {
12     cin>>n>>m>>k;
13      ll ans=0;
14     if(k>(n-1+m-1))
15     {
16         printf("-1\n");
17         return 0;
18     }
19     else
20     {
21         if(n-1>=k)
22         {
23            ans=max(ans,m*(n/(k+1)));
24         }
25         else
26         {
27             ans=max(ans,m/(k-(n-1)+1));
28         }
29         if(m-1>=k)
30         {
31             ans=max(ans,n*(m/(k+1)));
32         }
33         else
34         {
35             ans=max(ans,n/(k-m+2));
36         }
37     }
38     cout<<ans<<endl;
39     return 0;
40 }
View Code

 

posted @ 2015-03-14 16:37  null1019  阅读(103)  评论(0编辑  收藏  举报