CodeForces 449A - Jzzhu and Chocolate(贪心)
2017-01-18 22:27
369 查看
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 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
output
input
output
input
output
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.
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.
/*
题目链接:http://codeforces.com/contest/450/problem/C
题目意思:给出一个 n * m 大小的chocolate bar,你需要在这个bar上切 k 刀,使得最小的部分面积尽可能大,
求出这个被划分后的最小部分面积最大可以为多少。如果这个chocolate bar 不能切成 k 部分,则输出-1。
注意,每一刀需要符合3个条件:1、打横切或者打竖切; 2、每一刀只能经过unit square(即1*1的单元bar)的边,
也就是说不能把一个单元bar损坏,要完整;
3、每一刀只能在整个chocolate bar的里面操作,
也就是说,外围的四条边是不允许切的。
还有一个条件就是,每一刀都是不相同的。
if (n-1 >= k || m-1 >= k) 全部都横切或者竖切
else 先把横(或竖)全切了 把剩下的倒数拿去切竖(横)的
因为要求最小块 所以直接 除就行了
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <set>
#define pi acos(-1.0)
#define LL long long
#define ULL unsigned long long
#define inf 0x3f3f3f3f
#define INF 1e18#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
typedef pair<int, int> P;
const double eps = 1e-10;
const int maxn = 1e6 + 5;
const int N = 1e4 + 5;
const int mod = 1e8;
int main(void)
{
// freopen("in.txt","r", stdin);
LL n, m, k;
// 假定n为竖的 m为横的
while (cin >> n >> m >> k)
{
if (n + m - 2 < k){
cout << "-1" << endl;
continue;
}
LL ans = 0;
if (n-1 >= k) // 横切k次 因为切了k次有会有k+1份 所以n/(k+1)
ans = max(ans, m * (n/(k+1)));
if (m-1 >= k) // 竖切k次
ans = max(ans, n * (m/(k+1)));
if (n-1 < k) // 横切n-1次 竖切k-(n-1)次
ans = max(ans, m / (k-(n-1)+1));
if (m-1 < k) // 竖切m-1次 横切k-(m-1)次
ans = max(ans, n / (k-(m-1)+1));
cout << ans << endl;
}
return 0;
}
相关文章推荐
- jmail.dll发邮件用FOXMAIL收的话标题空格转为下划线?
- CodeForces757B
- Winform程序实现多显示屏、多屏幕显示的2种方法
- 生活,生活就是这样。面对,承受,调节,整理。
- 安装redis
- 2017.1.18【初中部 】普及组模拟赛C组 临时工计划 题解
- Mysql基础操作命令
- Mysql基础操作命令
- [oracle]索引与索引表管理
- JavaScript 中 for 循环
- JAVA基础——Java Synchronized
- CodeForces 448D - Multiplication Table(二分)
- CodeForces 593B - Anton and Lines(思维)
- HDU - 5269【SBBBBBB Trie】
- stl算法设计理念_一元函数对象和一元谓词
- Hadoop-2.7.3 单节点模式安装
- RGB图像存储为AVI?
- linux环境下的基础命令操作
- 新手进阶WebStorm工具的基本使用
- POJ 3295-Tautology(模拟-逻辑表达式)