数论 - 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 ...
随机推荐
- zabbix添加监控主机(三)
zabbix添加监控服务器. zabbix添加监控服务器(以添加10.10.100.137为例) (1)创建要监控的主机.点击配置(configuration)–>主机(host) –>创 ...
- Java Persistence with Hibernate
我们在Java中谈到持久化时,一般是指利用SQL在关系数据库中存储数据. ORM映射元数据,JPA支持XML和JDK 5.0注解两种元数据的形式,元数据描述对象和表之间的映射关系, 框架据此将实体对象 ...
- Angular-Chart.js 初接触;;;
可以先看下下面的链接,了解下, 推荐链接 准备工作 JS文件{angular.js.Chart.js.angular-chart.js} 这3个文件我的获取难易程度:Chart.js > ang ...
- 初次使用并安装express
安装 Nodejs 去Nodejs官网根据自己的操作系统下载对应的安装包并安装.我们就有了NodeJS和npm环境.npm是Node的包管理工具,会在安装NodeJS时一并安装.可以用以下命令查看版本 ...
- 【Alpha版本】 第一天 11.7
一.站立式会议照片: 二.项目燃尽图: 三.项目进展: 成 员 前段时间完成任务 今天完成任务 明天要做任务 问题困难 心得体会 胡泽善 部分APP功能 我要招聘详情的展示 注册界面的实现 一些特殊效 ...
- Redis学习 - 配置属性:bind
bind这个属性很容易理解成限制可以访问的IP地址,其实是指Redis服务器可以选择监听来自哪个网卡的访问请求.我们再用的时候一般都只有一个网卡,所以只能写本机的IP地址或者回路地址.否则在启动服务器 ...
- orm 语法 数据库连接、建表、增删改查、回滚、单键关联 、多键关联、三表关联
1.数据库连接, #!usr/bin/env/python # -*- coding:utf-8 -*- # from wangteng import sqlalchemy from sqlalche ...
- centOS 虚拟机设置固定IP:图形化设置
右键单击图形化标志,Edit Connection 设置一下就可以了.
- [mysql]知识补充
知识概况 视图 函数 存储过程 事务 索引 触发器 [视图] 视图是一个虚拟表,可以实现查询功能,不能进行增删改 本质:根据sql语句获取动态的数据集,并为其命名 1.创建视图 --create vi ...
- ajax返回数据类型为JSON数据的处理
JSON数据处理: 1.编码格式必须为utf8 2.echo json_encode($db->GuanQuery($sql)); 返回的是关联数组.json_encode返回的是json数 ...