B Buy Sticks

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值