Gym 100935E  Pairs

来源:互联网 发布:淘宝美工大师级 编辑:程序博客网 时间:2024/06/01 07:13
 Pairs
Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status Practice Gym 100935E

Description

standard input/output 
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

Input
215 9 7 15 6 12 13 16 21 1412 18 13 10 17 20 21 15 16 14
Output
Case 1: 2 4 5 10 11Case 2: 4 6 8 9 12

FAQ | About Virtual Judge | Forum | Discuss | Open Source 
把所有可能的组合理一下,就会发现组合数中最小的肯定是x1+x2,组合数最大的肯定是x4+x5。所以就可以推出x3.然后就可以一一求解了,类似解方程啊~
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<cctype>#include<stdio.h>#define min(a,b)(a<b?a:b)#define max(a,b)(a>b?a:b)#define INF 0x3f3f3f3ftypedef long long ll;using namespace std;int main(){    int T,i,s[11],x[6],ca;    ll sum;    scanf("%d",&T);    for(ca=1;ca<=T;ca++)    {        sum=0;        for(i=1;i<=10;i++)        {            scanf("%d",&s[i]);            sum += s[i];        }        sum=sum/4;        sort(s+1,s+11);        x[3]=sum-s[1]-s[10]; /// s[1]=x1+x2,s[10]=x4+x5;        x[1]=s[2]-x[3];        x[2]=s[1]-x[1];        x[5]=s[9]-x[3];        x[4]=s[10]-x[5];        sort(x+1,x+6);        printf("Case %d:",ca);        for(i=1;i<=5;i++)            printf(" %d",x[i]);        printf("\n");    }    return 0;}

0 0
原创粉丝点击