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

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的格子切k刀,求得到的最小格子数的最大值。

思路:贪心,先考虑都一个方向切,不够了再在还有一个方向切,尽量平均分。

AC代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <stdlib.h>
using namespace std;
typedef long long ll;
ll solve(int n,int m,int k){if(k<n) return 1LL*n/(k+1)*m;k-=n-1;return 1LL*m/(k+1);
}
int main(){int n,m,k;scanf("%d%d%d",&n,&m,&k);ll ans=max(solve(n,m,k),solve(m,n,k));if(k>n+m-2){cout<<-1;}else printf("%I64d",ans);return 0;
}


转载于:https://www.cnblogs.com/jhcelue/p/6816353.html

Codeforces Round #257 (Div. 2) C. Jzzhu and Chocolate相关推荐

  1. Codeforces Round #257 (Div. 1) D. Jzzhu and Numbers 高维前缀和 + 容斥

    传送门 文章目录 题意: 思路: 题意: 思路: 完全想不到容斥啊,看了半天也没看懂渍渍渍. 定义f[i]f[i]f[i]表示iii的超集个数,那么选择的方案就是2f[i]−12^{f[i]}-12f ...

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

    B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...

  3. Codeforces Round #257 (Div. 2)

    Codeforces Round #257 (Div. 2) https://codeforces.com/contest/450/ A 模拟 1 #include<bits/stdc++.h& ...

  4. hash+set Codeforces Round #291 (Div. 2) C. Watto and Mechanism

    题目传送门 1 /* 2 hash+set:首先把各个字符串的哈希值保存在set容器里,然后对于查询的每一个字符串的每一位进行枚举 3 用set的find函数查找是否存在替换后的字符串,理解后并不难. ...

  5. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  6. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

  7. 构造 Codeforces Round #302 (Div. 2) B Sea and Islands

    题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...

  8. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  9. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

最新文章

  1. 2022-2028年中国塑料人造革行业市场研究及前瞻分析报告
  2. 清明出游,你会“鸽”酒店吗?AI 早已看穿一切
  3. layui如何获取父节点的父节点_jquery获取父元素或父节点的方法
  4. Web开发环境搭建 Eclipse-Java EE 篇
  5. 大学生成绩管理系统(C语言)
  6. 拆分js文件_2021入门Webpack,看这篇就够了:Webpack.config.js 解析
  7. 关于 静态页面布局 中的一些BUG
  8. C# 数据库连接字符串拼接
  9. leecode第二百一十七题(存在重复元素)
  10. php 之 json格式
  11. lcs算法 php,使用PHP编写的LCS算法
  12. APP银联支付(微信、支付宝、云闪付)
  13. 云服务器哪家好?国内云服务器十大品牌排行榜
  14. 存储服务器 自建,搭建及了解存储服务器
  15. 2021年全新UI界面1:1仿皮皮虾APP段子
  16. Flex应用的易用性设计过程
  17. Beyond Part Models: Person Retrieval with Refined Part Pooling (and A Strong Convolutional Baseline)
  18. 从《我不是潘金莲》谈程序员的核心竞争力
  19. Android AsyncTask 接口回调
  20. 抖音上面那些暴力引流套路!赚到月入过万!

热门文章

  1. java 中的string_Java中String揭秘
  2. FCN论文-语义分割
  3. pytorch数据增强
  4. 基于深度学习的植物病害表征新视角
  5. matlab快速将几幅图片放在一幅图片
  6. 【java】方法中参数列表的应用
  7. php-java-bridge 作用_PHP-Java-Bridge的使用(平安银行支付功能专版)
  8. python获取同音字
  9. linux定位到文件,locate 在linux下快速定位文档
  10. java 集合数组 例子_Java数组元素去重(不使用集合)(示例代码)