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.
2 2 2 2
2 2 2 1
Case 1: 4
Case 2: 4
题意:就是知道四个人的箱子的边长,并且每个箱子都是正方向的,要求找到一个最小尺寸的并且能够装得下四个箱子没有重叠的最小边长。
思路:就是将四个数据排序,然后将四个数据的前两个较大的数相加,就能都满足要求。
代码如下:
<span style="font-size:14px;"><strong>#include<stdio.h> #include<algorithm> #include<string.h> using namespace std; int main() { int a[4]; int count=0; while(~scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])) { sort(a,a+4); printf("Case %d: %d\n",++count,a[3]+a[2]); memset(a,0,sizeof(a)); } return 0; }</strong></span>
原文地址:http://blog.csdn.net/ice_alone/article/details/38470195