主题链接:http://codeforces.com/problemset/problem/449/A

----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋http://user.qzone.qq.com/593830943/main

----------------------------------------------------------------------------------------------------------------------------------------------------------

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

题意:给出一个 n * m 大小的chocolate
bar。你须要在这个bar上切 k 刀,使得最小的部分面积尽可能大,求出这个被划分后的最小部分面积最大能够为多少。假设这个chocolate bar 不能切成 k 部分,则输出-1。

注意,每一刀须要符合3个条件:1、打横切或打竖切; 2、每一刀仅仅能经过unit square(即1*1的单元bar)的边,也就是说不能把一个单元bar损坏,要完整; 3、每一刀仅仅能在整个chocolate bar的里面操作,也就是说,外围的四条边是不同意切的。4、每一刀都是不同样的。

思路转载

首先要知道什么时候这个大bar不能切成 k 刀。

非常easy知道是假设k > (n-1)+(m-1) 的情况,由于外围的四条边是不同意操刀的!排除这个不能切的情况后。那么就要依据是从n(打横切)还是从m(打竖切)来进行讨论了。

只是由于我们不能一眼看出哪种方案更优。所以两者都要讨论下,我一開始仅仅想到 if 中的两条式子,n/(k+1)的意思表示这 k 刀都打横切,而分母为什么是k+1而不是k。是由于一刀能够把一个区域分成两部分,两刀就三个部分,依次类推。而我们须要求的是面积,就须要用到部分,而不是刀数了。m/(k+1)依此类推。

只是问题出现了。我依据test10返回的wa结果来想出的^_^。

有可能全然打横切或者打竖切都没有切够k刀!那么就须要把剩余的刀数分到打竖切(相应之前全然打横切)或者打横切(相应之前的全然打竖切)中了。

也就是代码中else的部分。事实上完整的a1表达式是这种:n/(n-1) * m/(k-(n-1)+1)。意思:全然打横切,仅仅能切n-1刀,那么它划分的最小部分的面积就充当1了,至于m/(k-(n-1)+1)
表示 打竖切还能切多少刀,+1是由于是求分成的部分,而不是多少刀,与if中的n/(k+1)中的+1意思是同样的。

(好开心这道题目排到最少用时的26名。继续努力!

^_^)

代码例如以下:

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL __int64
int main()
{
LL n, m, k;
LL ans1, ans2;
while(~scanf("%I64d%I64d%I64d",&n,&m,&k))
{
if(n-1+m-1 < k)
{
printf("-1\n");
continue;
}
if(n >= k+1 || m >= k+1)
{
ans1 = n/(k+1)*m;
ans2 = m/(k+1)*n;
}
else
{
ans1 = n/(k-(m-1)+1)*1;
ans2 = m/(k-(n-1)+1)*1;
}
LL ans = max(ans1, ans2);
printf("%I64d\n",ans);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪婪、数学)的更多相关文章

  1. Codeforces Round #257 (Div. 2) C. Jzzhu and Chocolate

    C. Jzzhu and Chocolate time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)

    题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...

  3. Codeforces Round #257(Div. 2) B. Jzzhu and Sequences(矩阵高速幂)

    题目链接:http://codeforces.com/problemset/problem/450/B B. Jzzhu and Sequences time limit per test 1 sec ...

  4. Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)

    题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...

  5. Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)

    题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...

  6. Codeforces Round #257 (Div. 2) B Jzzhu and Sequences

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  7. Codeforces Round #257 (Div. 1) D - Jzzhu and Numbers 容斥原理 + SOS dp

    D - Jzzhu and Numbers 这个容斥没想出来... 我好菜啊.. f[ S ] 表示若干个数 & 的值 & S == S得 方案数, 然后用这个去容斥. 求f[ S ] ...

  8. Codeforces Round #257 (Div. 2) A. Jzzhu and Children

    A. Jzzhu and Children time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. Codeforces Round #257(Div.2) D Jzzhu and Cities --SPFA

    题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路 ...

随机推荐

  1. Eclipse 快捷键整理

    Alt+/:代码提示Ctrl+/:注释/取消注释Ctrl+D:删除光标所在行Ctrl+K:将光标停留在变量上,按Ctrl+K键可以查找到下一个同样的变量Shift+Ctrl+K:和Ctrl+K查找的方 ...

  2. POJ 3181 Dollar Dayz 简单DP

    这DP虽然简单 但是思考一下还是挺好的 题意是 1,2,3,4....k 用加法凑成N 每个数可取不限个数 令dp[i][j] 表示前i种数凑成j的方案数 然后dp[i][j] = dp[i - 1] ...

  3. [Django]models定义choices 字典中的页面显示值

    问题: 在django的models.py 在.我们定义一些choices元组,类别似一些字典值.通常下拉框或单个复选框,例如 0相应的M 1妇女和其他有关 class Area(models.Mod ...

  4. codeforces55D数位dp

    codeforces55D 查询给定区间内的beautiful number.  一个数字是beautiful number当且仅当能被自己的各个数字不为0的位整除. 这个dp的状态还是挺难想的.一个 ...

  5. sql server从一个数据库复制一个表到另一个数据库的方法

    分两步进行: 第一步,复制表结构: 在表上面右击——>编写表脚本为:——>Create到——>新查询编辑器窗口,你也可以保存为sql文件, 将新查询编辑器窗口最上面的一句话USE [ ...

  6. 开源Math.NET基础数学类库使用(17)C#计算矩阵条件数

    原文:[原创]开源Math.NET基础数学类库使用(17)C#计算矩阵条件数                本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p ...

  7. js调用百度地图接口

    原文:js调用百度地图接口 这是前几天公司做的新项目,上面需要用到地图的数据.第一次做这类型的东西没啥思路,咱们经理说,这东西简单,截个图存文件夹里调整好尺寸,数据库里存上图片的地址动态调用就行了.心 ...

  8. Java中动态代理技术生成的类与原始类的区别

    用动态代理的时候,对它新生成的类长什么样子感到好奇.有幸通过一些资料消除了心里的疑惑. 平时工作使用的Spring框架里面有一个AOP(面向切面)的机制,只知道它是把类重新生成了一遍,在切面上加上了后 ...

  9. hdu1711 Number Sequence

    Problem Description Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], .... ...

  10. MongoDB学习笔记-维护

    主从复制 MongoDB有主从复制技术,解决高可用和容灾问题,也就是备份. 配置主从的特点: N 个节点的集群 任何节点可作为主节点 所有写入操作都在主节点上 自动故障转移 自动恢复 数据分布式存储 ...