励志用少的代码做高效表达


Problem describe

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的巧克力块,问用手掰或用刀切各需多少步才能把巧克力块变成N*M*K1*1*1的单元块。 用手掰一次只能掰一块,用刀切可以切一行或者一列。

用手掰:很好算: N*M*K-1即可。

用刀切:注意:切的过程中方块是可以改变位置 ,举例:切割长宽高为1*4*1的方块

这样,一共两刀即可将所有方块分割。

分析到这里,不难看出规律:

首先将长方体分为长宽高三个参数,分别考虑

每个参数分别切割的次数一定与2的幂次有关,即: 2^n<=长或宽或高, n取最大值。 如:4就切两刀,8就切三刀,若在4-8之间,则切3刀。(画一画就明白了)

贴上最后的代码

#include<bits/stdc++.h>
using namespace std;
int main() {int T; cin>>T; for(int i = 1; i <= T; i++) {long long l, w, h;  cin>>l>>w>>h;long long sum2=0;sum2 += ceil(1.0*log(l)/log(2));sum2 += ceil(1.0*log(w)/log(2));sum2 += ceil(1.0*log(h)/log(2));printf("Case #%d: %lld %lld\n", i, (l*w*h-1), sum2);}
return 0; }

14行代码AC_Break the Chocolate HDU-4112(数学推导+解析)相关推荐

  1. python爬虫代码1000行-简单用14行代码写一个Python代理IP的爬虫

    相信用别的语言只用14行是写不出来这样的效果的!而我们的Python 只需要区区的14行代码就能写出来哦! 这就是Python为什么是全球现在比较流行的语言之一了!因为简单 容易学! 比较上手! 现在 ...

  2. Python爬虫:想听榜单歌曲?使用BeautifulSoup库只需要14行代码即可搞定

    目录 BeautifulSoup库 安装BeautifulSoup库 BeautifulSoup库简介 选择解释器 基础用法 节点选择器 获取节点名称属性内容 获取所有子节点 获取所有子孙节点 父节点 ...

  3. 如何用 14 行代码制作 NFT

    如果您是对区块链开发感兴趣的开发人员,您应该对 NFT 或非同质代币有所了解.在本文中,我们将了解它们背后的工程,以便您开始构建自己的. 在项目结束时,您将拥有自己的以太坊钱包,其中包含一个新的 NF ...

  4. python首行代码import *,from * import * 解析

    python代码,一般第一行代码都是import *或from * import *,作用是导入功能模块,然后利用模块内的函数编写代码,减少大量的代码编写时间,是python的一大特色.但是,在实际写 ...

  5. 14行代码满分:1037 在霍格沃茨找零钱 (20分)

    立志用更少的代码做更高效的表达 PAT乙级最优题解-->传送门 如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 -- 就如海格告诉哈利的:"十七个银西可(Sickle)兑一个 ...

  6. 14行代码AC——1017 A除以B (20分)(大数运算+讲解)

    立志用更少的代码做更高效的表达 Pat乙级最优化代码+题解+分析汇总-->传送门 本题要求计算 A/B,其中 A 是不超过 1000 位的正整数,B 是 1 位正整数.你需要输出商数 Q 和余数 ...

  7. 14行代码AC_Zero Array(思维)

    立志用更少的代码做更高效的表达 You are given an array a1,a2,-,an.In one operation you can choose two elements ai an ...

  8. 27行代码AC_How Many Tables HDU - 1213(并查集讲解)

    励志用少的代码做高效表达 分析与思路 n个人吃饭,只能熟人和熟人坐在一起,否则就一个人坐一桌. 给定m个关系(m对熟人),问最少需要多少张桌子. 纯粹考查的并查集模板的题, 给定m个关系就代表了m个集 ...

  9. 14行代码AC_SCU 4440 Rectangle(公式+矩阵对称性)

    励志用少的代码做高效表达 Problem Describe frog has a piece of paper divided into (n) rows and (m) columns. Today ...

最新文章

  1. matplotlib命令与格式:图像(figure)与子区域(axes)布局与规划
  2. HDLBits 系列(34)Serial two's complememter(Mealy and Moore FSM)
  3. 面试:InnoDB 中一棵 B+ 树可以存放多少行数据?
  4. 一文告诉你,Intellij IDEA神器隐藏的11种实用小技巧!
  5. JVM年轻代,老年代,永久代详解
  6. 伸缩轨道_深度解析——伸缩喷漆房为什么这么受欢迎!
  7. Qt3D文档阅读笔记-Qt3D老版本知识点及使用新版本的运行
  8. [设计模式-创建型]建造者(Builder)
  9. 你写过哪些原创的风骨傲气,热血沸腾的句子?
  10. 你真的理解机器学习中偏差 - 方差之间的权衡吗?
  11. 如何确定autosar的版本_从工程师的角度看AUTOSAR
  12. 【激活函数】深度学习领域最常用的10个激活函数,一文详解数学原理及优缺点...
  13. java param=json字符串_java解析json字符串
  14. 开源流媒体服务器:为何一定得再撸个新的 | 凌云时刻
  15. 解决百度文库文档内容无法复制
  16. webSphere介绍
  17. Java/大数据常见面试
  18. tsm ANS0326E问题处理
  19. 新浪微博PC客户端(DotNet WinForm版)—— 初探
  20. 基于SpringBoot点餐小程序的开发【前后端】

热门文章

  1. python获取cookies
  2. python练习12
  3. 图文详解CDC技术,看这一篇就够了!
  4. 设计模式:工厂方法模式(Factory Method)和抽象工厂模式(Abstact Factory)
  5. 腾讯---生成格雷码
  6. 探索企业出海新机遇与音视频技术优化实践
  7. 音视频技术开发周刊 92期
  8. 腾讯AI Lab发布「电竞虚拟人」,视频版本一次看!
  9. nginx-rtmp message
  10. ubuntu 16.04 安装MXNet GPU版本