Break the Chocolate

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

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

题解:规律题,当用刀切时可以按每层来考虑,由于每一层都可以切完后放到自己上面,所以是log2 (x);三层加上即可;掰的时候就具体分析就好;

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#define c(x) (x==0?1:x)
const double DOX=0.999999999999999;
int main(){
int T,kase=0;
long long N,M,K;
scanf("%d",&T);
while(T--){
scanf("%lld%lld%lld",&N,&M,&K);
long long k1;
long long k2;
//k2=ceil(log2(K))+ceil(log2(M))+ceil(log2(N));也可以这样写
//ceil向上取整
k2=int(log2(K)+DOX)+int(log2(M)+DOX)+int(log2(N)+DOX);
k1=(long long)(K-1+K*(N-1)+K*N*(M-1));
printf("Case #%d: %lld %lld\n",++kase,k1,k2);
}
return 0;
}

  

Break the Chocolate(规律)的更多相关文章

  1. Codeforces Round #304 (Div. 2) Break the Chocolate 水题

    Break the Chocolate Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/546/ ...

  2. hdu 4112 Break the Chocolate 贪心

    Break the Chocolate Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem. ...

  3. HDU - 4112 Break the Chocolate(规律)

    题意:有一块n*m*k的巧克力,最终需要切成n*m*k个1*1*1的块,问用以下两种方法最少掰多少次能达到目的: 1.用手掰:每次只能拿出一块来掰:2.用刀切:可以把很多已经分开的块摞在一起一刀切下来 ...

  4. hdu 4112 Break the Chocolate(ceil floor)

    规律题: #include<stdio.h> #include<math.h> #define eps 1e-8 int main() { int _case; int n,m ...

  5. hdu 4112 Break the Chocolate(乱搞题)

    题意:要把一块n*m*k的巧克力分成1*1*1的单元,有两种操作方式:1,用手掰(假设力量无穷大),每次拿起一块,掰成两块小的:2,用刀切(假设刀无限长),可以把多块摆在一起,同时切开.问两种方式各需 ...

  6. Chocolate&&木块拼接&&Cards&& Wet Shark and Bishops

    B. Chocolate time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  7. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  8. Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索

    E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...

  9. Educational Codeforces Round 1 E. Chocolate Bar dp

    题目链接:http://codeforces.com/contest/598/problem/E E. Chocolate Bar time limit per test 2 seconds memo ...

随机推荐

  1. 并发编程:c++11 多线程中随机数重复问题

    srand(time(NULL)); 是我们熟悉的c++随机函数,用时间做种子.但由于在多线程环境下若想在子线程中随机出不同的随机数则需随机种子的不同.但time以秒计算,略显不足,故参考这篇文章解决 ...

  2. Nancy 搭建

    Nancy 框架 1.是一个轻量级用于构建http相应的web框架: 2.与mvc类似,有自己的路由机制: 3.可以处理 DELETE ,   GET ,   HEAD ,   OPTIONS ,   ...

  3. Hyper-v 安装CentOS

    http://www.cnblogs.com/dunitian/p/4976077.html

  4. 查看、修改oracle字符集,查看oracle版本

    1.查看数据库字符集 数据库服务器字符集select * from nls_database_parameters,其来源于props$,是表示数据库的字符集. 客户端字符集环境select * fr ...

  5. 《转》JAVA并发编程:volatile关键字解析

    volatile这个关键字可能很多朋友都听说过,或许也都用过.在Java 5之前,它是一个备受争议的关键字,因为在程序中使用它往往会导致出人意料的结果.在Java 5之后,volatile关键字才得以 ...

  6. Hadoop2.0安装

    http://blog.csdn.net/samhacker/article/details/18802223 http://blog.csdn.net/crazyhacking/article/de ...

  7. 黑马程序员_<<StringBuffer,包装类>>

    --------------------ASP.Net+Android+IOS开发..Net培训.期待与您交流! -------------------- 1. StringBuffer 1.概述 S ...

  8. Tempter of the Bone(dfs奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  9. JAVA訪问URL

    JAVA訪问URL: package Test; import java.io.BufferedReader; import java.io.IOException; import java.io.I ...

  10. std::map中函数用法集合

    1 STL的map表里有一个erase方法用来从一个map中删除掉指令的节点  2 eg:  3 map<string,string> mapTest;  4 typedef map< ...