码迷,mamicode.com
首页 > 其他好文 > 详细

HDU - 4112 Break the Chocolate

时间:2014-11-09 16:40:34      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   color   ar   os   sp   

Problem Description
bubuko.com,布布扣

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;
}




HDU - 4112 Break the Chocolate

标签:des   style   blog   http   io   color   ar   os   sp   

原文地址:http://blog.csdn.net/u011345136/article/details/40950607

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!