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、用手掰:n*1*1的巧克力需要掰n-1下,1*m*1的巧克力要m-1下,以此类推可知n*m*k的巧克力需要n*m*k-1下;

        2、用刀切:因为一次可以切多块巧克力,因此我们要使得切的巧克力每一次都尽可能的多,这就和二分差不多了,分别枚举长宽高,得出切n长的巧克力要几下才能到1,同理得出m和k,再相加即可

AC代码:

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

#define int long long

int f(int t)
{
	int cnt=1;
	int res=0;
	while(cnt<t)
	{
		res++;
		cnt*=2;
	}
	return res;
}

signed main()
{
	int n,m,k;
	int t;
	cin>>t;
	for(int l=1;l<=t;l++)
	{
		cin>>n>>m>>k;
		int res=n*m*k-1;
		printf("Case #%d: %lld %lld\n",l,res,f(n)+f(m)+f(k));
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Double.Qing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值