zoukankan      html  css  js  c++  java
  • cf 450c Jzzhu and Chocolate

    Jzzhu and Chocolate
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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.

    #include<iostream>
    #include<stdio.h>
    using namespace std;
    int main()
    {
        long long  n,m,k;
        while(~scanf("%I64d%I64d%I64d",&n,&m,&k))
        {
            if(n>=k+1||m>=k+1)
            {
                long long  maxx=max(n,m);
                long long  minn=min(n,m);
                long long  cl1=minn/(1+k);
                long long cl2=maxx/(1+k);
                //cout<<minn<<endl<<maxx<<endl<<cl1<<endl<<cl2<<endl;
                long long tmpma=0;
                long long tmpmi=0;
                 tmpmi=maxx*cl1;
                tmpma=minn*cl2;
                long long ans=max(tmpmi,tmpma);
                if(ans>0) printf("%I64d
    ",ans);
                    //printf("%I64d
    ",maxx/(k+1)*minn);
                continue;
            }
            long long  minn=min(n,m);
            long long maxx=max(n,m);
            long long  cl1=k-minn+1;
            long long cl2=k-maxx+1;
            //cout<<minn<<endl<<maxx<<endl<<cl1<<endl<<cl2<<endl;
            long long tmpma=0;
            long long tmpmi=0;
            if(cl1<maxx) tmpmi=maxx/(cl1+1);
            if(cl2<minn) tmpma=minn/(cl2+1);
            long long ans=max(tmpmi,tmpma);
            if(ans>0) printf("%I64d
    ",ans);
            else printf("-1
    ");
        }
        return 0;
    }//20180805
    View Code

    我感觉这道题是一种很巧妙的暴力,枚举可能的四种情况,取最大值。

  • 相关阅读:
    C++小结
    进程
    JavaScript中如何获取当前点击对象信息!
    form表单中enctype="multipart/form-data"的传值问题
    WebMagic框架总结
    工具类:自己总结的利用fileupload包上传文件的工具类!
    工具类:关于如何找到两个List数组中不同的数据的算法!
    工具类:关于解决数据库中的日期格式,经过response.getWriter().write(json)打到前台日期格式混乱的问题的总结
    工具类:将其他编码类型转换成UTF-8或者其他类型的工具类
    博主收藏的前端框架,极力推荐!
  • 原文地址:https://www.cnblogs.com/superxuezhazha/p/5474021.html
Copyright © 2011-2022 走看看