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 ------------------------------------------------------------------我是分割线^_^------------------------------------------------------------------ 题目的意思是原来有五个数,现在给定这些数两两相加的和,比如一开始的数为x1.x2.x3.x4.x5,那给定的十个和为x1+x2,
x1+x3,x1+x4.....x4+x5.....,就是这样,然后这题就是直接找一下基本就出来了,懵比的我偏偏还找了一个多小时,无语啊
实际上可以发现给定的十个数从小到大排序之后最小的和为x1+x2,最大的和为x4+x5,然后结合全局十个相加除以四为五
个数的和,就可以求出第三个数的了,求出第三个数之后再观察可以发现第二小的和是x1+x3,于是x1就求出来了,同理
可以得到x5(x3+x5是第二大的和),再重复观察就可全部求出来了,唉,真是平时不动脑筋不行呀= =
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
using namespace std; #define Int __int64
#define INF 0x3f3f3f3f typedef pair<int, int> pii; int main()
{
//freopen("input.txt", "r", stdin);
int n;
while (scanf("%d", &n) != EOF)
{
int sign = 1;
while (n--) {
int x[6] = {0};
int num[11];
int sum = 0;
for (int i = 1; i <= 10; i++) {
scanf("%d", &num[i]);
sum += num[i];
} sort(num + 1, num + 11); int s1 = sum / 4;
x[3] = s1 - num[1] - num[10];
x[1] = num[2] - x[3];
x[5] = num[9] - x[3];
x[2] = num[1] - x[1];
x[4] = num[10] - x[5];
printf("Case %d: ", sign++);
for (int i = 1; i <= 5; i++) {
printf("%d", x[i]);
if (i != 5) printf(" ");
else printf("\n");
}
}
}
return 0;
}

数论 - Pairs(数字对)的更多相关文章

  1. 剑指offer算法总结

    剑指offer算法学习总结 节选剑指offer比较经典和巧妙的一些题目,以便复习使用.一部分题目给出了完整代码,一部分题目比较简单直接给出思路.但是不保证我说的思路都是正确的,个人对算法也不是特别在行 ...

  2. [LeetCode] Find K Pairs with Smallest Sums 找和最小的K对数字

    You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define ...

  3. Project Euler 90:Cube digit pairs 立方体数字对

    Cube digit pairs Each of the six faces on a cube has a different digit (0 to 9) written on it; the s ...

  4. [Swift]LeetCode373. 查找和最小的K对数字 | Find K Pairs with Smallest Sums

    You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define ...

  5. Pairs Forming LCM (LightOJ - 1236)【简单数论】【质因数分解】【算术基本定理】(未完成)

    Pairs Forming LCM (LightOJ - 1236)[简单数论][质因数分解][算术基本定理](未完成) 标签: 入门讲座题解 数论 题目描述 Find the result of t ...

  6. [LeetCode] 373. Find K Pairs with Smallest Sums 找和最小的K对数字

    You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define ...

  7. [BZOJ 2154]Crash的数字表格(莫比乌斯反演+数论分块)

    [BZOJ 2154]Crash的数字表格(莫比乌斯反演+数论分块) 题面 求 \[\sum_{i=1}^{n} \sum_{j=1}^{m} \mathrm{lcm}(i,j)\] 分析 \[\su ...

  8. Lua Table pairs输出顺序问题 (版本差异 解决数字索引间断并兼容字符串索引)

    问题标签: Lua Table 迭代器;Lua Table 输出顺序; Lua Table 顺序输出;Lua Table 数字索引 字符串索引;Lua Table pairs; 问题背景: 使用pai ...

  9. UVa 12683 Odd and Even Zeroes(数论+数字DP)

    意甲冠军: 要求 小于或等于n号码 (0<=n <= 1e18)尾数的数的阶乘0数为偶数 思考:当然不是暴力,因此,从数论.尾数0数为偶数,然后,它将使N阶乘5电源是偶数.(二指数肯定少5 ...

随机推荐

  1. Druid初步学习

    Druid是一个JDBC组件,它包括三部分:  DruidDriver 代理Driver,能够提供基于Filter-Chain模式的插件体系. DruidDataSource 高效可管理的数据库连接池 ...

  2. [CentOs7]搭建ftp服务器

    摘要 vsftpd 是“very secure FTP daemon”的缩写,安全性是它的一个最大的特点.vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,它可以运行在诸如 Linux. ...

  3. golang笔记——流程控制

    条件语句 if ... else if ... else 语句,如: { fmt.Println(">100") } < num { fmt.Println(" ...

  4. loopback文档翻译

    最近在学习loopback,期间在strongloop的官网翻译了部分文章. 见:https://docs.strongloop.com/pages/viewpage.action?pageId=60 ...

  5. Node.js Stream-基础篇

    Node.js Stream - 基础篇 邹斌 ·2016-07-08 11:51 背景 在构建较复杂的系统时,通常将其拆解为功能独立的若干部分.这些部分的接口遵循一定的规范,通过某种方式相连,以共同 ...

  6. JavaScript闭包之“词法作用域”

    大家应该写过下面类似的代码吧,其实这里我想要表达的是有时候一个方法定义的地方和使用的地方会相隔十万八千里,那方法执行时,它能访问哪些变量,不能访问哪些变量,这个怎么判断呢?这个就是我们这次需要分析的问 ...

  7. python解析git log后生成页面显示git更新日志信息

    使用git log可以查到git上项目的更新日志. 如下两个git项目,我想把git的日志信息解析成一个便于在浏览器上查看的页面. https://github.com/gityf/lua https ...

  8. linux 配置ssh免密码登陆本机

    1.安装 sudo apt-get install ssh 2.配置无密码登录 ssh-keygen -t rsa 遇到停顿按回车即可 进入/home/zeze/.ssh目录(隐藏目录,在winSCP ...

  9. python写计算器

    #!/usr/bin/env python # -*- coding:utf-8 -*- import re def chu(arg1): #定义加减 arg = arg1[0] #beacuse p ...

  10. linux c 笔记-2 Hello World & main函数

    按照惯例撸一个hello_world.c #include <stdio.h> int main(int argc, char * argv[]) { printf("hello ...