HDU - 4112 Break the Chocolate

Problem Description

Benjamin is going to host a party for his big promotion coming up.

Every party needs candies, chocolates and beer, and of course Benjamin has prepared some of those. But as everyone likes to party, many more people showed up than he expected. The good news is that candies are enough. And for the beer, he only needs to buy
some extra cups. The only problem is the chocolate.

As Benjamin is only a ‘small court officer‘ with poor salary even after his promotion, he can not afford to buy extra chocolate. So he decides to break the chocolate cubes into smaller pieces so that everyone can have some.

He have two methods to break the chocolate. He can pick one piece of chocolate and break it into two pieces with bare hand, or put some pieces of chocolate together on the table and cut them with a knife at one time. You can assume that the knife is long enough
to cut as many pieces of chocolate as he want.

The party is coming really soon and breaking the chocolate is not an easy job. He wants to know what is the minimum number of steps to break the chocolate into unit-size pieces (cubes of size 1 × 1 × 1). He is not sure whether he can find a knife or not, so
he wants to know the answer for both situations.

Input

The first line contains an integer T(1<= T <=10000), indicating the number of test cases.

Each test case contains one line with three integers N,M,K(1 <=N,M,K <=2000), meaning the chocolate is a cube of size N ×M × K.

Output

For each test case in the input, print one line: "Case #X: A B", where X is the test case number (starting with 1) , A and B are the minimum numbers of steps to break the chocolate into N × M × K unit-size pieces with bare hands and knife respectively.

Sample Input

2
1 1 3
2 2 2

Sample Output

Case #1: 2 2
Case #2: 7 3

题意:给你立方体的巧克力,让你用手掰,和用刀切弄成1*1*1的小巧克力分别最少用多少,用刀切,可以不管有多少块

思路:掰的话,肯定要sum-1次,切的话,因为可以多块一起切,所以我们分别考虑长,宽,高,分别要多少次,才能切成小块,结果是log2(len),分别统计相加就是了

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
typedef long long ll;
using namespace std;

int main() {
	int t, n, m, k, cas = 1;
	scanf("%d", &t);
	while (t--) {
		scanf("%d%d%d", &n, &m, &k);
		ll ans = 1ll * n * m * k;
		int cnt = 0;
		cnt += ceil(1.0 * log(n) / log(2));
		cnt += ceil(1.0 * log(m) / log(2));
		cnt += ceil(1.0 * log(k) / log(2));
		printf("Case #%d: ", cas++);
		cout << ans-1 << " " << cnt << endl;;
	}
	return 0;
}
时间: 2024-10-07 05:26:32

HDU - 4112 Break the Chocolate的相关文章

hdu 4112 Break the Chocolate 贪心

Break the Chocolate Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4112 Description Benjamin is going to host a party for his big promotion coming up.Every party needs candies, chocolates and beer, and of cour

HDU 4112 Break the Chocolate(简单的数学推导)

Break the Chocolate Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4556    Accepted Submission(s): 1458 Problem Description Benjamin is going to host a party for his big promotion coming up.Eve

HDU - 4112 Break the Chocolate(规律)

题意:有一块n*m*k的巧克力,最终需要切成n*m*k个1*1*1的块,问用以下两种方法最少掰多少次能达到目的: 1.用手掰:每次只能拿出一块来掰:2.用刀切:可以把很多已经分开的块摞在一起一刀切下来 分析: 1.用手掰,需要n*m*k-1次. 2.用刀切,可以分别考虑长宽高,计算长宽高分别切成单位长度所需要的最少次数,相加即可. 二分切,可得最少次数.规律为,长度为x最少需切ceil(log2(x))次. #include<cstdio> #include<algorithm>

HDU - 3644:A Chocolate Manufacturer&#39;s Problem(模拟退火, 求多边形内最大圆半径)

pro:给定一个N边形,然后给半径为R的圆,问是否可以放进去.  问题转化为多边形的最大内接圆半径.(N<50): sol:乍一看,不就是二分+半平面交验证是否有核的板子题吗. 然而事情并没有那么简单.  因为我们的多边形可能是凹多边形,而前面的方法只对凸多边形有效. 学习了下模拟退火的算法,这个随机算法只在最小圆覆盖的时候写过. 这里再学一下,看起来更正宗一点的.  每次在当前点的附近(R)找是否能优化,而这个R慢慢变小,使得趋紧答案的趋势更精细. 判定点再多边形内:同样,不能用检验是否在每条

hdu 4112

Problem Description Benjamin is going to host a party for his big promotion coming up.Every party needs candies, chocolates and beer, and of course Benjamin has prepared some of those. But as everyone likes to party, many more people showed up than h

[GodLove]Wine93 Tarining Round #4

比赛链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=44903#overview 题目来源: 2011 Asia ChengDu Regional Contest Wine93有话说: 爆0, oh-year!   ID Origin Title   13 / 118 Problem A HDU 4111 Alice and Bob 137 / 358 Problem B HDU 4112 Break the Chocolate

codeforces 598E E. Chocolate Bar(区间dp)

题目链接: E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you ma

Sharing Chocolate - UVa 1099 状压dp

Chocolate in its many forms is enjoyed by millions of people around the world every day. It is a truly universal candy available in virtually every country around the world. You find that the only thing better than eating chocolate is to share it wit

Codeforces Round #340 (Div. 2) B

Description Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes