Gym 100935E E. Pairs (模拟)

E. Pairs
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

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.

Examples
input
2
15 9 7 15 6 12 13 16 21 14
12 18 13 10 17 20 21 15 16 14
output
Case 1: 2 4 5 10 11
Case 2: 4 6 8 9 12
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <stack>
#include <iostream>
#include <string>
using namespace std;
const int MAXN = 1e1 + 5;
const int MAXM =1e3 + 5;
typedef long long LL;
int A[MAXN];
int n;
int B[MAXN];
map<int,int>F;
bool C() {
	for(int i = 1; i <= 5; i ++) {
		for(int j = 1; j < i; j ++) {
			if(B[i] == B[j]) return false;
			if(!F[B[i] + B[j]]) return false;
		}
	}
	return true;
}
int main() {
	int cas = 1;
	while(~scanf("%d", &n)) {
		while(n --) {
			F.clear();
			for(int j = 1; j <= 10; j ++) {
				scanf("%d", &A[j]);
				F[A[j]] = 1;
			}
			sort(A + 1, A + 10 + 1);
			for(int i = 10; i > 0; i --) {
				B[5] = (A[9] - A[2] + A[i]) / 2;
				B[1] = B[5] - A[9] + A[2];
				B[2] = A[1] - B[1];
				B[3] = A[2] - B[1];
				B[4] = A[10] - B[5];
				if(C()) {
					break;
				}
			}

			printf("Case %d: %d %d %d %d %d\n",cas ++,B[1], B[2], B[3], B[4], B[5]);
		}
	}
	return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值