数论 - 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 ...
随机推荐
- Google map markers
现已被屏蔽 http://mabp.kiev.ua/2010/01/12/google-map-markers/ Надо по немногу отходить от празднывания но ...
- [Head First设计模式]生活中学设计模式——状态模式
系列文章 [Head First设计模式]山西面馆中的设计模式——装饰者模式 [Head First设计模式]山西面馆中的设计模式——观察者模式 [Head First设计模式]山西面馆中的设计模式— ...
- PHP cookie
PHP Cookie cookie 常用于识别用户. Cookie 是什么? cookie 常用于识别用户.cookie 是一种服务器留在用户计算机上的小文件.每当同一台计算机通过浏览器请求页面时,这 ...
- sql 查询
select * from (select * ,row_number() over(partition by CreateUID order by asid)num from AuctionSell ...
- jquery numberbox赋值
numberbox不能使用$('#id').val( '');只能使用$('#id').numberbox('setValue','');
- Bestcoder#5 1003
Bestcoder#5 1003 Poor RukawTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- Linux学习之一--VI编辑器的基本使用
vi编辑器是Linux系统下标准的编辑器.而且不逊色于其他任何最新的编辑器.可是会用的有多少呢.下面介绍一下vi编辑器的简单用法和部分命令.让你在Linux系统中畅行无阻. 基本上vi可以分为三种状态 ...
- Linux 架构
(转)作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! http://www.cnblogs.com/vamei/archive/2 ...
- React 还是 Vue: 你应该选择哪一个Web前端框架?
学还是要学的,用的多了,也就有更多的认识了,开发中遇到选择的时候也就简单起来了. 本文作者也做了总结: 如果你喜欢用(或希望能够用)模板搭建应用,请使用Vue 如果你喜欢简单和“能用就行”的东西 ...
- h5页面 禁止缩放
<head><meta name="viewport" content="width=device-width,minimum-scale=1.0,ma ...