Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪婪、数学)
主题链接:http://codeforces.com/problemset/problem/449/A
----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋:http://user.qzone.qq.com/593830943/main
----------------------------------------------------------------------------------------------------------------------------------------------------------
1 second
256 megabytes
standard input
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.
A single line contains three integers n, m, k (1 ≤ n, m ≤ 109; 1 ≤ k ≤ 2·109).
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
3 4 1
6
6 4 2
8
2 3 4
-1
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(贪婪、数学)的更多相关文章
- 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 ...
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)
题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...
- 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 ...
- Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)
题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)
题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...
- 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 ...
- Codeforces Round #257 (Div. 1) D - Jzzhu and Numbers 容斥原理 + SOS dp
D - Jzzhu and Numbers 这个容斥没想出来... 我好菜啊.. f[ S ] 表示若干个数 & 的值 & S == S得 方案数, 然后用这个去容斥. 求f[ S ] ...
- 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 ...
- Codeforces Round #257(Div.2) D Jzzhu and Cities --SPFA
题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路 ...
随机推荐
- 学了Java 你未必知道这些
作为一个正奔跑向编程完美天堂的朝圣者,本人觉得在平常的编程中,应该要做到以下几点: 一:汝应注释,这样做既方便别人,也方便自己去读懂代码的逻辑 二:注重细节,为自己写的每行代码负责,比如,在并发编程的 ...
- POJ 1696 Space Ant(点积的应用)
Space Ant 大意:有一仅仅蚂蚁,每次都仅仅向当前方向的左边走,问蚂蚁走遍全部的点的顺序输出.開始的点是纵坐标最小的那个点,開始的方向是開始点的x轴正方向. 思路:从開始点開始,每次找剩下的点中 ...
- 怎样在万网加入Lync Online SRV记录
万网已经支持SRV记录解析了,可是有好几个朋友问我怎么加入SRV记录(假设域名提供商不支持,能够通过DNSPOD来实现),过程例如以下 1:绑定域名至Office 365 略,请查看我的视频或者博客中 ...
- Django中的一些同步Model和数据库的命令
1 最简单而又令人兴奋的命令: manage.py syncdb 创建了指定app中的model相应的数据库表,假设是第一次使用此命令,会提示是否创建超级用户,输入username,Email和pas ...
- phpcms v9框架的目录结构分析
phpcms v9框架的目录结构分析: 了解v9框架的目录结构,有助于帮助我们快速建立起对v9框架的一个整体认识 打开"mycms"项目,有如下文件和目录 使用 ...
- ASP.NET之Cookie(坑爹的Response.Cookies.Remove)
原文:ASP.NET之Cookie(坑爹的Response.Cookies.Remove) 在web开发中Cookie是必不可少的 .NET自然也有一个强大的Cookie操作类,我们用起来也非常方便, ...
- WPF Delegate委托整理
那啥,是从这里整理出来的,感谢Rising_Sun,整理的过于简单,看不明白的戳这里 using System; using System.Collections.Generic; using Sys ...
- Google的Guava它Collection升华
至于Guava这是不是在这里说.一个已被提上一个非常特殊的! 这主要是为了分享Guava对于一些升华处理组.井,不多说了,直接在代码: package com.joyce.guava.bean; /* ...
- uip UDPclient模式通信移植,p本地ort可以是无规
现在移植UDPclient模式,使用广播地址检测. //udp_client.c /********************************************************** ...
- [Windows Phone] 地图覆叠层控制项(MapOverlay )
原文:[Windows Phone] 地图覆叠层控制项(MapOverlay ) 前言 当使用地图时,我们可能需要定位一些座标图示或是绘制一些文字线条,这时可以在地图上加上覆叠层进行绘制,在 Wind ...
