数论 - Pairs(数字对)
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.
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.
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.
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 ------------------------------------------------------------------我是分割线^_^------------------------------------------------------------------ 题目的意思是原来有五个数,现在给定这些数两两相加的和,比如一开始的数为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(数字对)的更多相关文章
- 剑指offer算法总结
剑指offer算法学习总结 节选剑指offer比较经典和巧妙的一些题目,以便复习使用.一部分题目给出了完整代码,一部分题目比较简单直接给出思路.但是不保证我说的思路都是正确的,个人对算法也不是特别在行 ...
- [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 ...
- 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 ...
- [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 ...
- Pairs Forming LCM (LightOJ - 1236)【简单数论】【质因数分解】【算术基本定理】(未完成)
Pairs Forming LCM (LightOJ - 1236)[简单数论][质因数分解][算术基本定理](未完成) 标签: 入门讲座题解 数论 题目描述 Find the result of t ...
- [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 ...
- [BZOJ 2154]Crash的数字表格(莫比乌斯反演+数论分块)
[BZOJ 2154]Crash的数字表格(莫比乌斯反演+数论分块) 题面 求 \[\sum_{i=1}^{n} \sum_{j=1}^{m} \mathrm{lcm}(i,j)\] 分析 \[\su ...
- Lua Table pairs输出顺序问题 (版本差异 解决数字索引间断并兼容字符串索引)
问题标签: Lua Table 迭代器;Lua Table 输出顺序; Lua Table 顺序输出;Lua Table 数字索引 字符串索引;Lua Table pairs; 问题背景: 使用pai ...
- UVa 12683 Odd and Even Zeroes(数论+数字DP)
意甲冠军: 要求 小于或等于n号码 (0<=n <= 1e18)尾数的数的阶乘0数为偶数 思考:当然不是暴力,因此,从数论.尾数0数为偶数,然后,它将使N阶乘5电源是偶数.(二指数肯定少5 ...
随机推荐
- 10月28日上午 PHP数据访问
1.建一个连接(连接PHP和MYSQL) $db = new MySQLi("localhost","root","666","t ...
- ecshop 实现购物车退出不清空
ecshop模板在使用过程中会遇到会员退出再登陆时购物车里面的商品会被清空掉的,通过ecshop开发中心的技术,整理的文档,对程序做简单修改即可实现会员退出不清空购物车 ECShop版本:V2.7.3 ...
- 安装 Ruby, Rails 运行环境 常见的错误
安装部署ruby on rails 的环境时并不是想的那么顺利 这个是我遇到的问题及解决的方式 参考安装博客: (1) https://ruby-china.org/wiki/install_ruby ...
- tyvj1097 mm不哭
背景 Bless all rp++.. 描述 在一个数轴上,有n个MM(绝非恐龙!)在哭泣(5555~一直哭). tcboy也在这个数轴上,并恰好看到了这一幕,由于每个MM哭都会让tcboy损失一定的 ...
- eclipse version
查看Eclipse的版本号: 1. 找到eclipse安装目录 2. 进入readme文件夹,打开readme_eclipse.html 3. readme_eclipse.html呈现的第二行即数字 ...
- (原)android补间动画(四)之插补器Interpolator
比如说一段旋转动画 RotateAnimation animation = new RotateAnimation(0, 360, mMoveCircle.getMeasuredWidth() / 2 ...
- SQLPULS : 密码中有特殊字符的处理方法
前日在使用SQLPLUS访问oracle数据库时,系统提示密码过期,需要更新密码.于是不假思索的修改密码为xxx@2016(估计当时脑子抽风了),造成了杯具的开始. 再次进入SQLPLUS,输入用户名 ...
- ACM/ICPC 之 卡卡的矩阵旅行-最小费用最大流(可做模板)(POJ3422)
将每个点拆分成原点A与伪点B,A->B有两条单向路(邻接表实现时需要建立一条反向的空边,并保证环路费用和为0),一条残留容量为1,费用为本身的负值(便于计算最短路),另一条残留容量+∞,费用为0 ...
- jqueyr eq get用法
相信大部份人都会把这2个的用法搞错.仔细查看下API文档就可以知道.eq返回的是一个jquery对象,get返回的是一个html 对象数组.举个例子: <p style="color: ...
- 使用jquery实现单选框、多选框取消选中状态
function radioReset(){ /*方式一*/ /* var radios = $("input[type='radio']"); for (i=0; i<ra ...