HDU 4112 2011ACM成都现场赛B

 

Break the Chocolate

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 46    Accepted Submission(s): 12


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
 

Source
 
这是现场赛最简单的一道,很多牛校在很短的时间内就AC了
不过题目有个trick,就是要超int
 
我的代码:
#include<stdio.h>
#include<math.h>

int main()
{
	__int64 n,m,k,ans1,ans2,t,T;
	scanf("%I64d",&T);
	for(t=1;t<=T;t++)
	{
		scanf("%I64d%I64d%I64d",&n,&m,&k);
		ans1=n*m*k-1;
		ans2=(__int64)(ceil(log(n*1.0)/log(2.0))+ceil(log(m*1.0)/log(2.0))+ceil(log(k*1.0)/log(2.0)));
		printf("Case #%I64d: %I64d %I64d\n",t,ans1,ans2);
	}
	return 0;
}

阅读更多
个人分类: 数学
想对作者说点什么? 我来说一句

2008年ACM-ICPC成都赛区现场赛题目

2013年03月16日 128KB 下载

2012ACM成都赛区现场赛题目

2012年11月11日 92KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭