博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Break the Chocolate(规律)
阅读量:6827 次
发布时间:2019-06-26

本文共 2521 字,大约阅读时间需要 8 分钟。

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
#include
#include
#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;}

  

 

转载地址:http://arezl.baihongyu.com/

你可能感兴趣的文章
Vysor在最新版chrome的正确打开方式
查看>>
JAVA 多用户商城系统b2b2c---配置中心和消息总线
查看>>
为什么v-for中的key值不推荐使用index
查看>>
java垃圾回收-读书笔记《深入理解java虚拟机》
查看>>
留学本科没毕业你也对留学的价值产生怀疑了吗?
查看>>
Redis数据结构
查看>>
金三银四,所有人都应该知道的事
查看>>
SQLServer之触发器简介
查看>>
这个俄罗斯大神,又出新作品了!
查看>>
用vuepress搭建一个够自己用的博客
查看>>
AMD(中文版)
查看>>
Tomcat的web应用加载过程
查看>>
小程序挖坑之路
查看>>
MySQL 数据类型
查看>>
changelog 日志自动生成插件
查看>>
Eventloop不可怕,可怕的是遇上Promise
查看>>
如何让textarea随着内容自适应高度
查看>>
用Flex实现常见的几种布局
查看>>
前端错误日志上报相关实践
查看>>
使用SQLAlchemy添加数据库数据时,db.session.commit()报错:InvalidRequestError: This Session'......
查看>>