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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

HDU 3573(详解+思路+代码)

發布時間:2024/8/23 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 3573(详解+思路+代码) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Description

Imyourgod need 3 kinds of sticks(樹枝)?which have different sizes: 20cm, 28cm and 32cm. However the shop only sell 75-centimeter-long sticks. So he have to cut off the long stick. How many sticks he must buy at least.

Input

The first line of input contains a number t, which means there are t cases of the test data.?
There will be several test cases in the problem, each in one line. Each test cases are described by 3 non-negtive-integers separated by one space representing the number of sticks of 20cm, 28cm and 32cm. All numbers are less than 10^6.

Output

The output contains one line for each line in the input case. This line contains the minimal number of 75-centimeter-long sticks he must buy. Format are shown as Sample Output.

Sample Input

2

3 1 1

4 2 2

Sample Output

Case 1: 2

Case 2: 3

題意:XX需要3種不同尺寸的樹枝:20cm28cm、和32cm。然而這商店僅僅銷售75厘米長的樹枝。

因此他不得不砍掉長得樹枝。問至少需要買多少樹枝?

輸入:

第一行包含一個數字t,表示t組測試數據,多組測試數據,每組測試數據占一行,每組通過

三個用一個空格間隔的非負數分別代表20cm28cm32cm樹枝的數量

輸出:

輸出占用一行,輸出至少買76cm長數的數量

思路:容易出錯的地方就是樹是可以切的但是并不能連接,好比75切成20 28cm那么剩下的22cm是沒有用的只能棄掉,因此有以下幾種情況:

1、一根76cm全切成20cm或者28cm最多3

2、一根76cm全切成32cm最多兩根

3、一根76cm切成任意兩種樹枝,但出現三種類型的樹都有則至少需要兩根

因此我們用a b c 表示三種情況的樹枝的數量:

利用模擬法挨個遞減可做,但是有優先級需要考慮。

代碼:

#include<iostream> #include<algorithm> #include<cstdio> using namespace std;int main() {int t;cin>>t;for(int i=1;i<=t;i++){__int64 a,b,c;__int64 sum;int ans=0;cin>>a>>b>>c;while(a>=2&&c>=1){ //72a-=2;c--;ans++;}while(a>=2&&b>=1){ //68a-=2;b--;ans++;}while(a>=3){ //68a-=3;ans++;}while(c>=2){ //64c-=2;ans++;}while(b>=1&&c>=1){ //60b--;c--;ans++;}while(b>=2){ //56b-=2;ans++;}if(a||b||c)ans++;printf("Case %d: %d\n",i,ans);}return 0; }

總結

以上是生活随笔為你收集整理的HDU 3573(详解+思路+代码)的全部內容,希望文章能夠幫你解決所遇到的問題。

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