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种不同尺寸的树枝:20cm、28cm、和32cm。然而这商店仅仅销售75厘米长的树枝。
因此他不得不砍掉长得树枝。问至少需要买多少树枝?
输入:
第一行包含一个数字t,表示t组测试数据,多组测试数据,每组测试数据占一行,每组通过
三个用一个空格间隔的非负数分别代表20cm、28cm和32cm树枝的数量
输出:
输出占用一行,输出至少买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){ //72
a-=2;
c--;
ans++;
}
while(a>=2&&b>=1){ //68
a-=2;
b--;
ans++;
}
while(a>=3){ //68
a-=3;
ans++;
}
while(c>=2){ //64
c-=2;
ans++;
}
while(b>=1&&c>=1){ //60
b--;
c--;
ans++;
}
while(b>=2){ //56
b-=2;
ans++;
}
if(a||b||c)
ans++;
printf("Case %d: %d\n",i,ans);
}
return 0;
}