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