【2013】四个小正方形放入大正方形

41 篇文章 0 订阅
27 篇文章 2 订阅

问题描述:
Mr. B, Mr. G, Mr. M and their coach Professor S are planning their way 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:
There are N test cases. The first line is N.

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.

Sample Input:
2
2 2 2 2
2 2 2 1
Sample Input:
Case 1: 4
Case 2: 4
题意:
给出四个正方形边长,将这四个正方形放入一个大正方形中,求大正方形的最小边长

思路:
最小边长即为四条边中最大两个边之和(要想取得最小边长,必须有两个正方形相邻,这样最小边长就由最大的两条边来决定)

#include <cstdio>
#include <algorithm>
using namespace std;
 
int main(){
    int a[4];
    int n;
    scanf("%d", &n);
    int count = 0;
    while(n--){
        for(int i = 0; i < 4; i++){
            scanf("%d", &a[i]);
        }
        sort(a, a+4);
        printf("Case %d: %d\n",++count, a[2]+a[3]);
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值