(CF#257)C. Jzzhu and Chocolate

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 exactlyk 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.

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.

啊啊啊啊,没写出来,原来想二分来着,可是不好弄,看别人思路做的,其实也挺好理解的。。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
    long long  n,m,k;
    while(cin>>n>>m>>k)
    {
        long long maxn=0;
        if(k>n+m-2)
        {
            cout<<-1<<endl;
            continue;
        }
        if(k<n)  maxn=max(maxn,m*(n/(k+1)));//k刀分成k+1分
        if(k<m)  maxn=max(maxn,n*(m/(k+1)));
        if(k>=n) maxn=max(maxn,m/(k-n+2));//(k-(n-1)+1;
        if(k>=m) maxn=max(maxn,n/(k-m+2));
        cout<<maxn<<endl;
    }
    return 0;
}

(CF#257)C. Jzzhu and Chocolate

时间: 2024-10-02 00:08:36

(CF#257)C. Jzzhu and Chocolate的相关文章

(CF#257)B. Jzzhu and Sequences

Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn modulo 1000000007 (109?+?7). Input The first line contains two integers x and y (|x|,?|y|?≤?109). The second line contains a single i

(CF#257)A. Jzzhu and Children

There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to n. The i-th child wants to get at least ai candies. Jzzhu asks children to line up. Initially, the i-th child stands at the i

Codeforces Round #257 (Div. 2)449A - Jzzhu and Chocolate(贪心、数学)

题目链接:http://codeforces.com/problemset/problem/449/A ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

Codeforces 450C:Jzzhu and Chocolate(贪心)

C. Jzzhu and Chocolate time limit per test: 1 seconds 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 exact

Codeforces449A Jzzhu and Chocolate &amp;&amp; 449B Jzzhu and Cities

CF挂0了,简直碉堡了.两道题都是正确的思路但是写残了.写个解题报告记录一下心路历程. A题问的是 一个n*m的方块的矩形上切k刀,最小的那一块最大可以是多少.不难发现如果纵向切k1刀,横向切k2刀,那么答案应该是 (n/(k1+1)) * (m/(k2+1)),除法是取整的.虽然是取整,但是不难发现其实就是要(k1+1)*(k2+1)最小,根据均值不等式,k1+k2=k(定值) k1==k2的时候(k1+1)*(k2+1)=k1*k2+k1+k2+1=k1*k2+k+1应该是取最大值,所以当k

CodeForces 449A - Jzzhu and Chocolate

传送门:Jzzhu and Chocolate 题意: 给出一个N * M的矩阵,给K个操作,每次操作可以横/竖切割矩阵,最后求K次切割之后,矩阵最小的那块面积最大是多少? 分析: 按照题意,题目求的结果是:(最小的面积,最大是多少),那么可以想到,K次切割之后尽量使得每个块的面积相等,某些块比较大(因为不一定能平均分),那么就可以使得最小的那块面积最大了. 然后如何切割呢? 因为有横竖两个切割方法,那么我们可以设X为横切割数,Y为竖切割数,其中(0 <= X, Y <= K),因为最多对一个

【机器学习算法-python实现】协同过滤(cf)的三种方法实现

(转载请注明出处:http://blog.csdn.net/buptgshengod) 1.背景 协同过滤(collaborative filtering)是推荐系统常用的一种方法.cf的主要思想就是找出物品相似度高的归为一类进行推荐.cf又分为icf和ucf.icf指的是item collaborative filtering,是将商品进行分析推荐.同理ucf的u指的是user,他是找出知趣相似的人,进行推荐.通常来讲icf的准确率可能会高一些,通过这次参加天猫大数据比赛,我觉得只有在数据量非

449A - Jzzhu and Chocolate 贪心

一道贪心题,尽量横着切或竖着切,实在不行在交叉切 #include<iostream> #include<stdio.h> using namespace std; int main(){ // freopen("in.txt","r",stdin); long long n,m,k; while(cin>>n>>m>>k){ if((n+m-2)<k){ printf("-1\n"

zz [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

http://yidianzixun.com/n/09vv1FRK?s=1 完全摘抄自网页 1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在Web 应用中利用集体智慧构建更加有趣的应用或者得到更好的用户体验.集体智慧是指在大量的人群的行为和数据中收集答案,帮助你对整个人群得到统计意义上的结论,这些结论是我们在单个个体上无法得到的,它往往是某种趋势或者人群