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
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 ",++kase,k1,k2); } return 0; }