HDU-#4112 Break the Chocolate(规律)
来源:互联网 发布:环信java服务端demo 编辑:程序博客网 时间:2024/06/05 07:59
题目大意:将一块N*M*K的巧克力分解成1*1*1的大小块,按照手工分和用刀切两种方式,问分别最少需要多少步?
解题思路:通过对案例进行分析,可以得出对于手工,因为只能一次一次地分解,需要n*m*k-1次。对于刀切,可以对于同一个型号进行一切分解,每一次的目标都最终分解成2次幂的形式,因此列举数据分析可以,对于大于1的长度需要切接近2次幂的上限数。解法详见code。
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=4112
code:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define ll __int64ll n,m,k,a,b;int t,cas;ll gao(ll x){ ll cnt=0,tmp=2; while(x>=tmp){ cnt++; tmp*=2; if(x>tmp/2 && x<tmp) ++cnt; } return cnt;}int main(){ //freopen("input.txt","r",stdin); cas=0; scanf("%d",&t); while(t--){ a=0;b=0; scanf("%I64d%I64d%I64d",&n,&m,&k); a=n*m*k-1; if(n>1) b+=gao(n); if(m>1) b+=gao(m); if(k>1) b+=gao(k); printf("Case #%d: %I64d %I64d\n",++cas,a,b); } return 0;}
0 0
- HDU-#4112 Break the Chocolate(规律)
- HDU 4112 Break 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
- HDU - 4112 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 二分
- hdu4112-规律&二进制- Break the Chocolate
- [HDU 4112]Break the Chocolate[YY推公式]
- 学校1051 巧克力 ||HDU 4112 Break the Chocolate
- HDOJ 题目4112Break the Chocolate(数学)
- Break the Chocolate(推论题)
- GUN ASM概述
- ubuntu分辨率设置
- 判断点与多边形的位置关系
- [无限互联]IOS之MMdrawer框架的使用及实现原理
- sevlet 链接数据库的问题
- HDU-#4112 Break the Chocolate(规律)
- ubuntu设置分辨率
- [Java Web]Struts2基础总结(二)
- Visual Studio控制台程序输出窗口一闪而过的解决方法
- mysql varchar max
- 【ACdream】Andrew Stankevich's Contest (3)
- javascript作用域
- 联想教育应用使用说明(7.6版本)——第3章 联想教育应用的日常维护与使用
- oracle触发器