B Buy Sticks

来源:互联网 发布:行业数据 编辑:程序博客网 时间:2024/05/27 00:50

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