CodeForces 449AJzzhu and Chocolate(贪心)
来源:互联网 发布:大数据的定义是什么 编辑:程序博客网 时间:2024/05/16 19:21
CodeForces 449AJzzhu and Chocolate(贪心)
CodeForces 449A
题目大意:
一块N*M的巧克力,指定K次切割,切割的要求看题目。问能否使得最小的那块巧克力的面积最大。如果不能进行K次切割输出-1.
解题思路:
要使得切割后最小的巧克力的面积最大,那么尽量是朝一个方向切割是最优的。
代码:
#include <cstdio>typedef long long ll;ll N, M, K;ll max (ll a, ll b) { return a > b ? a: b;}ll min(ll a, ll b) { return a < b ? a: b;}ll handle(ll x, ll y) { ll a = N/(x + 1); a = min(a, N - a*x); ll b = M/(y + 1); b = min(b, M - b*y); return a * b;}ll solve () { ll x = max(K - N + 1, 0); ll y = max(K - M + 1, 0); return max(handle(K - x, x), handle(y, K - y));}int main () { while (scanf ("%lld%lld%lld", &N, &M, &K) != EOF) { if (K > (N + M) - 2) { printf ("-1\n"); continue; }/* if (N > M) { ll t = N; N = M; M = t; } if (K + 1 <= M) { if (N % (K + 1) == 0) printf ("%lld\n", N /(K + 1) * M); else if (M % (K + 1) == 0) printf ("%lld\n", M /(K + 1) * N); else printf ("%lld\n", solve()); } else printf ("%lld\n", max(min(N/(K - M + 2), N - (N/(K - M + 2))*(K - M + 1)), min(M/(K - N + 2), M - (M/(K - N + 2) * (K - N + 1)))));*/ printf ("%lld\n", solve()); }}
0 0
- CodeForces 449AJzzhu and Chocolate(贪心)
- Codeforces 449A Jzzhu and Chocolate(贪心)
- CodeForces 449A - Jzzhu and Chocolate(贪心)
- CODEFORCES 450C Jzzhu and Chocolate <贪心>
- Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪心、数学)
- Jzzhu and Chocolate - CF 449C 贪心
- 449A - Jzzhu and Chocolate 贪心
- 【杂题】 codeforces 449A Jzzhu and Chocolate
- CodeForces 449-A. Jzzhu and Chocolate
- CodeForces 449A Jzzhu and Chocolate
- Codeforces 449 A Jzzhu and Chocolate
- CodeForces 449A - Jzzhu and Chocolate
- Codeforces Jzzhu and Chocolate
- Alice, Bob and Chocolate CodeForces
- Codeforces Round #257 (Div. 2)449A - Jzzhu and Chocolate
- CodeForces 449 A.Jzzhu and Chocolate(枚举)
- codeforces 6C - Alice, Bob and Chocolate
- Codeforces 450 C. Jzzhu and Chocolate
- css背景图片位置采点工具 css sprites
- Java静态变量初始化时机
- java 汉字排序(java.text.Collator)
- Tomcat 7优化前及优化后的性能对比
- ImageLoader 基本介绍及使用
- CodeForces 449AJzzhu and Chocolate(贪心)
- MySQL安装
- python 的sqlite3使用详解
- BIO-NIO-AIO(Java版)
- SAT填空基础练习题(二) 含答案
- 第三章第41题 哥德巴赫猜想
- windows下python运行的方法
- 第二章第27题
- 【leetcode】3sums