B Buy Sticks

來源:互聯網
上載者:User

Problem Description

Imyourgod need 3 kinds of sticks which havedifferent sizes: 20cm, 28cm and 32cm. However the shop only sell75-centimeter-long sticks. So he have to cut off the long stick. How manysticks 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 testcases are described by 3 non-negtive-integers separated by one spacerepresenting the number of sticks of 20cm, 28cm and 32cm. All numbers are lessthan 10^6.

 Output

The output contains one line for each line inthe input case. This line contains the minimal number of 75-centimeter-longsticks 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

摘自HDOJ 3573!

這道題比較簡單,首先當然是先將一根75cm長的棍子分成三段最理想, 有如下3種分法:

A、20+20+28

B、20+20+30

C、20+20+20

我們可以分為三步:

    第一步當然是盡量先切出A、B兩種,也就是切出一個28(或32)和兩個20;

    第二步是看20的數目夠不夠(>=3),能切出三段20來不;

    第三步時,三種長度的棍子剩下的情況如何呢?想想……

    (還能切出3段不?呃……不能了!那剩下的就切兩段吧!)

#include<iostream>using namespace std;int main(){    int i,j,k;    int cases;    int n = 0;    cin>>cases;    while( n < cases)    {                int a, b, c;                cin>>a>>b>>c;                int res = 0;                                if((b+c)*2 >= a)                res  += a/2 + (b+c-a/2+a%2+1)/2;                else res += (b+c) + (a - 2*(b+c) + 2)/3;                      cout<<"Case "<<(n+1)<<": "<<res<<endl;                     n++;                     }    //system("pause");    return 0;    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.