日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2024/2/28 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 14行代码AC_Break the Chocolate HDU-4112(数学推导+解析) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

勵志用少的代碼做高效表達


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*K個1*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; } 超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的14行代码AC_Break the Chocolate HDU-4112(数学推导+解析)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 超级黄色片 | 日本老妇高潮乱hd | 亚洲最新偷拍 | 精品人妻无码在线 | 国模私拍一区二区三区 | 免费成人深夜夜行p站 | 欧美少妇毛茸茸 | 久久久久久久麻豆 | 老子午夜影院 | 毛片基地在线观看 | 老司机一区二区三区 | 2020亚洲天堂 | 超碰成人在线免费观看 | 国产破处在线 | 男同av在线观看一区二区三区 | 亚洲国产精选 | 99激情视频| av最新| 日韩少妇裸体做爰视频 | 国产免费www | 九九热视频精品在线观看 | 91无打码| 久久99国产综合精品免费 | 免费看毛片的网站 | 99精品久久久久久久 | 亚洲第一色网站 | 亚洲h在线观看 | 日韩中文字幕网站 | 国产精品jizz视频 | 精品黑人一区二区三区国语馆 | 亚洲成人黄色av | 久久精品2019中文字幕 | 人操人视频 | 欧美在线精品一区二区三区 | 天堂中文av在线 | 亚洲综合视频网 | 久久久高潮 | 青青草91 | 亚洲乱码精品久久久久.. | 香港一级纯黄大片 | 香蕉视频黄在线观看 | 第一色影院 | 日本黄色一区 | 麻豆出品 | 四季av一区二区凹凸精品 | 久久国产精品久久国产精品 | 日本加勒比在线 | 67194少妇在线观看 | 免费看黄在线 | 一区视频在线播放 | 亚洲欧美一区二区在线观看 | 欧美日韩1区2区 | 国产欧美日韩免费 | 91小宝寻花一区二区三区 | 黄色在线免费网站 | www.五月婷婷.com | 午夜视频精品 | 国产毛片在线视频 | 乌克兰毛片 | 国产高清一区二区三区 | 亚洲一久久 | 91av在线免费| 成人免费观看视频 | 日韩av一区二区在线观看 | 国产一区激情 | 久久精品毛片 | 成人先锋av | 欧美黑人又粗又大又爽免费 | 狠狠干一区| 亚洲影院中文字幕 | 视频一区二区三区在线观看 | 色婷亚洲 | 国产午夜精品理论片 | 黄色长视频 | 88xx成人永久免费观看 | 黄色香蕉软件 | 黑鬼巨鞭白妞冒白浆 | 久久免费视频2 | 亚洲天堂欧美在线 | 国产欧美一区二区三区在线看蜜臀 | 久久久久久久久久福利 | 午夜电影网站 | 国产乱码精品一区二区三区五月婷 | 97成人精品| 久久久99国产精品免费 | 天天操夜夜草 | av一区不卡 | 色老头网址 | 日韩精品人妻无码一本 | av在线第一页| 国产人妻互换一区二区 | 日本孰妇毛茸茸xxxx | 欧美色图一区二区 | 日日噜噜夜夜狠狠久久波多野 | 神马影院午夜伦理片 | 成年人黄色一级片 | 国产精品毛片一区二区三区 | 亚洲六月丁香色婷婷综合久久 | 亚洲午夜精品 |