HDU 6168 Numbers
来源:互联网 发布:php开发基础入门 编辑:程序博客网 时间:2024/06/05 22:32
Problem Description
zk has n numbers a1,a2,...,an . For each (i,j) satisfying 1≤i<j≤n, zk generates a new number (ai+aj) . These new numbers could make up a new sequence b1,b2,...,bn(n−1)/2 .
LsF wants to make some trouble. While zk is sleeping, Lsf mixed up sequence a and b with random order so that zk can't figure out which numbers were in a or b. "I'm angry!", says zk.
Can you help zk find out which n numbers were originally in a?
LsF wants to make some trouble. While zk is sleeping, Lsf mixed up sequence a and b with random order so that zk can't figure out which numbers were in a or b. "I'm angry!", says zk.
Can you help zk find out which n numbers were originally in a?
Input
Multiple test cases(not exceed 10).
For each test case:
∙ The first line is an integer m(0≤m≤125250), indicating the total length of a and b. It's guaranteed m can be formed as n(n+1)/2.
∙ The second line contains m numbers, indicating the mixed sequence of a and b.
Eachai is in [1,10^9]
For each test case:
Each
Output
For each test case, output two lines.
The first line is an integer n, indicating the length of sequence a;
The second line should contain n space-seprated integersa1,a2,...,an(a1≤a2≤...≤an) . These are numbers in sequence a.
It's guaranteed that there is only one solution for each case.
The first line is an integer n, indicating the length of sequence a;
The second line should contain n space-seprated integers
It's guaranteed that there is only one solution for each case.
Sample Input
62 2 2 4 4 4211 2 3 3 4 4 5 5 5 6 6 6 7 7 7 8 8 9 9 10 11
Sample Output
32 2 261 2 3 4 5 6
Source
2017 Multi-University Training Contest - Team 9
题意:
给出数组C 数组C由数组A、B组成
数组B由数组A两两相加所得
求原数组A
题解:
首先排个序 一定可以确定最小的两个元素是原数组A
因为没有任何数字相加可以得到这两个最小的元素
齐次 用这两个最小的元素丢进multiset中 erase相加所得的元素
然后再用齐次小的两个元素
#include<stdio.h>#include<string.h>#include<set>#define ll long longusing namespace std;const int MAX = 1e6;int ans[MAX];int main(){ int m; while(~scanf("%d",&m)){ multiset<int>s; for(int i = 0;i < m;i++){ int x; scanf("%d",&x); s.insert(x); } int cnt = 0; ans[cnt++] = *s.begin(); s.erase(s.begin()); while(!s.empty()){ ans[cnt++] = *s.begin(); s.erase(s.begin()); for(int i = 0;i < cnt - 1;i++){ s.erase(s.lower_bound(ans[cnt-1] + ans[i])); } } printf("%d\n",cnt); for(int i = 0;i < cnt;i++){ if(i) printf(" %d",ans[i]); else printf("%d",ans[i]); } puts(""); } return 0;}
阅读全文
0 0
- HDU 6168 Numbers(排序)
- HDU 6168 Numbers
- HDU 6168 Numbers
- hdu--6168--Numbers
- HDU 6168 Numbers
- HDU 6168 Numbers
- HDU 6168 Numbers【水题】
- hdu 6168 Numbers
- hdu 6168 Numbers【map】
- HDU 6168 Numbers
- HDU 6168-Numbers
- HDU 6168 Numbers
- hdu 6168 Numbers
- hdu-6168 Numbers
- HDU 6168 Numbers 思维
- HDU 6168 Numbers 思维
- Hdu 6168 Numbers【思维+暴力】
- hdu 6168 Numbers (STL)
- MOTOx4虽被人吐槽的外形,但这一点你肯定喜欢
- SpringMVC 控制器写多个方法(非注解方式)
- 状态模式
- 计算图(computational graph)角度看BP(back propagation)算法
- 黑盒测试_边界值分析法
- HDU 6168 Numbers
- Eureka
- python中web服务器和web框架之间的规范 小白深度理解WSGI
- Spring Cloud源码分析Ribbon
- sql server 列信息查询
- AFNetworking怎么post x-www-form-urlencoded类型的数据
- Java面试宝典2015版(绝对值得收藏超长版)(一)
- linux ubuntu 16.04 deb文件的安装
- 程序员笑话...