A famous ICPC team
Time limit:1000 msMemory limit:0 KB64bit Io format:% LLD & % LlU
Mr. b, mr. g, mr. m and their coach processors sor 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 shocould 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 22 2 2 1
Output: Case 1: 4Case 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 cocould find the side length of the box must be at least 4.
Thought: in fact, it is to find the sum of the longest two sides,
The side length of the four cube boxes is given, and the minimum length of the large cube side of the four cube boxes can be asked.
The four boxes must have the minimum side length and four boxes. Therefore, the four boxes must be stacked on two layers. Therefore, the side length is determined by the length of the two longest side cubes.
Code:
#include <iostream>#include <algorithm>using namespace std;int main(){ int x[4]; int t=1; while(cin>>x[0]>>x[1]>>x[2]>>x[3]) { sort(x,x+4); cout<<"Case "<<t++<<": "<<x[2]+x[3]<<endl; } return 0;}
#include<stdio.h>#include<stdlib.h>int cmp(const void *a,const void *b){ return *(int *)a-*(int *)b;}int main(){ int side[4]; int i=1; while(~scanf("%d",&side[0])) { for(int j=1;j<4;j++) { scanf("%d",&side[j]); } qsort(side,4,sizeof(side[0]),cmp); printf("Case %d: ",i); printf("%d\n",side[2]+side[3]); i++; }return 0;}