SPOJ - TEAM2 A Famous ICPC Team

Description

Mr. B, Mr. G, Mr. M and their coach Professor S are planning their way to Warsaw for the ACM-ICPC World Finals. Each of the four has a square-shaped suitcase with side length Ai (1 <= i <= 4) respectively. They want to pack their suitcases into a large square box. The heights of the large box as well as the four suitcases are exactly the same. So they only need to consider the large box’s side length. Of course, you should write a program to output the minimum side length of the large box so that the four suitcases can be put into the box without overlapping.

Input

Each test case contains only one line containing 4 integers Ai (1<= i <=4, 1<= Ai <=1,000,000,000) indicating the side length of each suitcase.

Output

For each test case, display a single line containing the case number and the minimum side length of the large box required.

Example

Input:
2 2 2 2
2 2 2 1

Output:
Case 1: 4
Case 2: 4

Explanation

For the first case, all suitcases have size 2x2. So they can perfectly be packed in a 4x4 large box without wasting any space.

For the second case, three suitcases have size 2x2 and the last one is 1x1. No matter how to rotate or move, you could find the side length of the box must be at least 4.

【题目大意】B先生,G先生,M先生和他们的教练S正计划前往华沙参加ACM-ICPC世界总决赛。他们四个中的每一个都有一个方形手提箱,边长分别为A_iAi​(1 <= i <= 4)。 他们想把所有的行李箱装进一个大方箱里。 大箱子和四个手提箱的高度完全相同。 所以他们只需要考虑大箱子的边长。 编写一个程序来输出大盒子的最小边长,这样四个手提箱就可以放入盒子而不会重叠。 

【题解】 

只要两个最大的小方箱放在一起(不论竖着摆还是横着摆),那么其余的两个小方箱放置时,边长一定不会超过这两个最大小方箱的边长(也不论竖着摆还是横着摆) 。

至于怎样找到边长第一和第二大的小方箱,我们可以用数组输入,最后一个sort就行了。

#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    int a[5];
    int t = 1;
    while (~scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3])){
        sort(a, a+4);
        printf("Case %d: %d\n", t++, a[2]+a[3]);
    }
        
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

牧心.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值