Break the Chocolate(推论题)
来源:互联网 发布:汽车租赁管理系统源码 编辑:程序博客网 时间:2024/05/21 09:44
链接:http://www.bnuoj.com/bnuoj/contest_show.php?cid=2279#problem/25271
B. Break the Chocolate
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
解析:
题意:
给出一个N*M*K巧克力,使其变1*1*1的一块块。
这里要求计算两种操作的最少操作数:
1.仅用手掰,每一次只能把一整块掰成两部分
2.用刀切,可以任意切
思路:
1.用手掰:考虑N,M,K三个量,最终是K-1+K*((M-1)+M*(N-1))
=K*N*M-1;
2.刀切:与2的幂相关。
ans=ceil(log2(N))+ceil(log2(M))+ceil(log2(K));
注:
函数名: ceil
用 法: double ceil(double x);
功 能: 返回大于或者等于指定表达式的最小整数
头文件:math.h。
31 ms 292 KB [ 558 B ]
*/
#include<stdio.h>#include<math.h>#include<string.h>#include <iostream>using namespace std;int main(){int T,i,j,ca=0;__int64 s2,s1,c,a[4],t;scanf("%d",&T);while(T--){scanf("%I64d%I64d%I64d",&a[0],&a[1],&a[2]);s1=a[2]-1+a[2]*((a[0]-1)+a[0]*(a[1]-1));s2=0; for(i=0;i<3;i++) { t=0; c=1; while(c<a[i]) { c*=2; t++; } s2+=t; }printf("Case #%d: %I64d %I64d\n",++ca,s1,s2);} return 0;}
- Break the Chocolate(推论题)
- [HDU 4112]Break the Chocolate[YY推公式]
- HDU 4112 Break the Chocolate(模拟)
- HDU-#4112 Break the Chocolate(规律)
- Reginal2011_Chengdu_B Break the Chocolate
- hdu4112: Break the Chocolate
- Break the Chocolate HDU
- HDU 4112 Break the Chocolate
- hdu-4112-Break the Chocolate
- hdu 4112 Break the Chocolate
- HDU - 4112 Break the Chocolate
- HDU - 4112 Break the Chocolate
- HDOJ 题目4112Break the Chocolate(数学)
- hdoj Break the Chocolate 4112 (数学规律题)
- hdu 4112 Break the Chocolate(数学函数)
- hdu 4112 Break the Chocolate(模拟)
- hdu 4112 Break the Chocolate(水题)
- hdu 4112 Break the Chocolate 二分
- CAN项目---遇到的问题
- Hdu 1247 Hat’s Words (Trie动态写法+STL) + UVa 11732 strcmp() Anyone (Trie的另一种建立方法)
- Oracle 锁和阻塞
- 潜入维基解密机房:探访维基总部
- Android系统获取当前的时间转化为当前的字符串
- Break the Chocolate(推论题)
- java基础知识————for循环几种写法
- const 内存分配
- Android常用UI布局的介绍
- 19. 方便不是-ility
- mingW与cygwin 异同
- oracle实用基本操作
- UIBarButtonItem学习
- 关于eclipse中安装maven插件的问题