Description
Statements
In the secret book of ACM, it’s said: “Glory for those who write short ICPC problems. May they live long, and never get Wrong Answers” . Everyone likes problems with short statements. Right? Let’s have five positive numbers: X1,X2,X3,X4,X5. We can form 10 distinct pairs of these five numbers. Given the sum of each one of the pairs, you are asked to find out the original five numbers.
Input
The first line will be the number of test cases T. Each test case is described in one line which contains 10 numbers, these are the sum of the two numbers in each pair. Notice that the input has no particular order, for example: the first number doesn’t have to be equal to {X1+ X2}. All numbers are positive integers below 100,000,000.
Output
For each test case, print one line which contains the number of the test case, and the five numbers X1,X2,X3,X4,X5 in ascending order, see the samples and follow the output format. There always exists a unique solution.
Sample Input
2
15 9 7 15 6 12 13 16 21 14
12 18 13 10 17 20 21 15 16 14
Case 1: 2 4 5 10 11
Case 2: 4 6 8 9 12
/* 数学题5个数任意组合出十个数,给出你这10个数,让你求出原始的5个数 推理 x1+x2一定=s1 s4+s5=s10 得出x3=sum-s1-s10; sum就是5个数的和,这十个数,五个中每个数字用4次 然后解方程就可以了 */ #include<stdio.h> #include<iostream> #include<algorithm> #include<string.h> #include<vector> #include<map> #define N 11 using namespace std; int main() { //freopen("in.txt","r",stdin); int t; int ans[N]; int cur[N]; long long sum=0; scanf("%d",&t); for(int l=1;l<=t;l++) { sum=0; for(int i=1;i<=10;i++) { scanf("%d",&ans[i]); sum+=ans[i]; } sum/=4; sort(ans+1,ans+11); //cout<<sum<<endl; cur[3]=sum-ans[1]-ans[10]; cur[1]=ans[2]-cur[3]; cur[2]=ans[1]-cur[1]; cur[5]=ans[9]-cur[3]; cur[4]=ans[10]-cur[5]; //cout<<cur[3]<<endl; //for(int i=1;i<=5;i++) // printf(" %d",cur[i]); //printf(" "); sort(cur+1,cur+6); printf("Case %d:",l); for(int i=1;i<=5;i++) printf(" %d",cur[i]); printf(" "); } return 0; }