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

题目链接: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 刀。很容易知道是如果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;
}
时间: 2024-08-15 00:12:20

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

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

题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路的权值大于该点最短距离的显然可以删去,否则将该条边加入图中,再求最短路,记录每个点的前一个点,然后又枚举铁路,已经删去的就不用处理了,如果铁路权值大于该点最短距离又可以删去,权值相等时,该点的前一个点如果不为1,则这个点可以由其他路到达,这条铁路又可以删去. 由于本题中边比较多,最多可以有8x10^

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

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

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

题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. 1 /* 2 | 1, -1 | | fn | 3 | 1, 0 | | fn-1 | 4 */ 5 #include <iostream> 6 #include <cstdio> 7 #include <cstring> 8 using namespace std; 9 typedef __int64 LL; 10 LL mod =

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, 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

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

D - Jzzhu and Numbers 这个容斥没想出来... 我好菜啊.. f[ S ] 表示若干个数 & 的值 & S == S得 方案数, 然后用这个去容斥. 求f[ S ] 需要用SOSdp #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces Round #257 div.2 D or 450D Jzzhu and Cities【最短路】

Codeforces Round #257 div.2 D or 450D Jzzhu and Cities[最短路] 题目链接:点击打开 题目大意: 在一个国家中有n个城市(城市编号1~n),m条公路和k条铁路,编号为1的城市为首都,为了节约,不需要的铁路需要关闭,问在保证首都到其余所有城市的最短路不变的条件下,最多有多少条铁路是不需要的. 解法: 这个题比较麻烦,保证首都到其余城市的最短路不变,要求出最多有多少条铁路是不需要的,那肯定是从最短路的代码上下手了,我们首先考虑dijkstra算法

Codeforces Round #257 (Div. 2)

A.Jzzhu and Children 计算每个人会出现的轮次数,取最后一个且轮次数最大的,注意是用a[i]-1 % m,倒着扫一遍就行了 #include <iostream> #include <cstdio> #include <cstdlib> using namespace std; const int maxn = 100+10; int n, m; int a[maxn]; int main() { #ifdef LOCAL freopen("

Codeforces Round #257 (Div. 2) A/B/C/D

前三题早就写好了,一直在纠结D A. Jzzhu and Children 题意:就是简单的模拟,给排成一队的孩子分发糖果,每个孩子有至少要得到的糖果数. 然后每次给队头的孩子分发m个糖果,如果他已经得到了足够的糖果(大于等于他想得到的 最少糖果数)那么他就出队,否则他就去队尾.问最后一个孩子的编号. 算法:队列模拟,水题~ #include<cstdio> #include<iostream> #include<cstring> #include<queue&g