现在的位置: 首页 > 综合 > 正文

Codeforces 449 A Jzzhu and Chocolate

2019年02月23日 ⁄ 综合 ⁄ 共 816字 ⁄ 字号 评论关闭

题目链接~~>

做题感悟:这题确实很坑,列方程列了两个小时也没A掉,真是弱爆了。。。

解题思路:

                 给你 n * m 的方格,那么,行最多可以切 n - 1 下,列最多可以切 m - 1 下, 那么我们可以假设行切 x 下,列切 y 下,最终得到的面积为 n / ( x + 1)  * m / ( y + 1) ,且 x + y = k ,要使面积最大,就得让(x+1) * ( y + 1) 最小 ,那么 x 与 y 的差必须要尽量大,于是就取极端值就可以了。

代码:

#include<iostream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<fstream>
#include<sstream>
#include<stack>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<cstdio>
#include<algorithm>
#define INT __int64
using namespace std ;
const double esp = 0.00000001 ;
const int INF = 9999999 ;
const int mod = 1e9 + 7 ;
const int MY = 100 + 10 ;
const int MX = 100 + 10 ;
int main()
{
    INT n , m ,k ;
    while(~scanf("%I64d%I64d%I64d" ,&n ,&m ,&k))
    {
        if(n > m)  swap(n ,m) ;
        if(n+m-2 < k)  cout<<"-1"<<endl ;
        else
        {
            INT Max = -1 ;
            if(k <= n-1)
            {
                Max = max(Max ,n/(k+1)*m) ;
                Max = max(Max ,m/(k+1)*n) ;
            }
            else if(k > n-1 && k <= m-1)
                Max = max(m/(k+1)*n ,Max) ;
            else
                Max = max(n/(k-m+2) ,Max) ;
            cout<<Max<<endl ;
        }
    }
    return 0 ;
}

抱歉!评论已关闭.