HDU 3573(详解+思路+代码)

40 篇文章 3 订阅
15 篇文章 1 订阅

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种不同尺寸的树枝:20cm28cm、和32cm。然而这商店仅仅销售75厘米长的树枝。

因此他不得不砍掉长得树枝。问至少需要买多少树枝?

输入:

第一行包含一个数字t,表示t组测试数据,多组测试数据,每组测试数据占一行,每组通过

三个用一个空格间隔的非负数分别代表20cm28cm32cm树枝的数量

输出:

输出占用一行,输出至少买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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值