(全国多校重现赛一) H Numbers
zk has n numbers a1,a2,...,ana1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk generates a new number (ai+aj)(ai+aj). These new numbers could make up a new sequence b1,b2,...,bn(n−1)/2b1,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?
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.
Each aiai is in [1,10^9]
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 integers a1,a2,...,an(a1≤a2≤...≤an)a1,a2,...,an(a1≤a2≤...≤an). These are numbers in sequence a.
It's guaranteed that there is only one solution for each case.
Sample Input
6
2 2 2 4 4 4
21
1 2 3 3 4 4 5 5 5 6 6 6 7 7 7 8 8 9 9 10 11
Sample Output
3
2 2 2
6
1 2 3 4 5 6
这个看代码吧。QAQ
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n,m;
vector <int> a,b,c,ans;
map <int,int> mmp;
int main()
{
while(~scanf("%d",&n))
{
a.clear();
b.clear();
c.clear();
ans.clear();
mmp.clear();
int temp;
for(int i=0;i<n;i++)
{
scanf("%d",&temp);
a.push_back(temp);
if(mmp[temp]==0) mmp[temp]=1;
else mmp[temp]++;
}
sort(a.begin(),a.end());
ans.push_back(a[0]);
for(int i=1;i<n;i++)
{
if(mmp[a[i]]==0) continue;
for(int j=0;j<ans.size();j++)
{
mmp[ans[j]+a[i]]--;
}
ans.push_back(a[i]);
mmp[a[i]]--;
}
printf("%d\n",ans.size());
vector <int> ::iterator it;
for(it=ans.begin();it!=ans.end();it++)
{
if(it==ans.begin()) cout<<*it;
else cout<<" "<<*it;
}
cout<<endl;
}
return 0;
}
(全国多校重现赛一) H Numbers的更多相关文章
- (全国多校重现赛一)D Dying light
LsF is visiting a local amusement park with his friends, and a mirror room successfully attracts his ...
- (全国多校重现赛一)F-Senior Pan
Senior Pan fails in his discrete math exam again. So he asks Master ZKC to give him graph theory pro ...
- (全国多校重现赛一) J-Two strings
Giving two strings and you should judge if they are matched. The first string contains lowercase le ...
- (全国多校重现赛一)E-FFF at Valentine
At Valentine's eve, Shylock and Lucar were enjoying their time as any other couples. Suddenly, LSH, ...
- (全国多校重现赛一)B-Ch's gifts
Mr. Cui is working off-campus and he misses his girl friend very much. After a whole night tossing a ...
- (全国多校重现赛一)A-Big Binary Tree
You are given a complete binary tree with n nodes. The root node is numbered 1, and node x's father ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位dp)
题目链接:https://ac.nowcoder.com/acm/contest/163/J 题目大意:给定一个数N,求区间[1,N]中满足可以整除它各个数位之和的数的个数.(1 ≤ N ≤ 1012 ...
- 长春理工大学第十四届程序设计竞赛(重现赛)H.Arithmetic Sequence
题意: 数竞选手小r最喜欢做的题型是数列大题,并且每一道都能得到满分. 你可能不相信,但其实他发现了一个结论:只要是数列,无论是给了通项还是给了递推式,无论定义多复杂,都可以被搞成等差数列.这样,只要 ...
随机推荐
- nyoj 844-A+B Problem(V) (string[::-1] 字符串反转)
844-A+B Problem(V) 内存限制:64MB 时间限制:1000ms 特判: No 通过数:14 提交数:17 难度:1 题目描述: 做了A+B Problem之后,Yougth感觉太简单 ...
- 管道 |、|&、tee
用“|”或“|&”隔开两个命令之间形成一个管道,左边命令的标准输出(|)或者标准错误输出(|&)信息流入到右边命令的标准输入,即左边命令的标准输出作为右边命令的标准输入.如: make ...
- error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
用Python打开图像始终提示错误 error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\highgui\src\window.c ...
- JavaScript中解析JSON --- json.js 、 json2.js 以及 json3.js的使用区别
JSON官方(http://www.json.org/)提供了一个json.js,json.js是JSON官方提供的在JavaScript中解析JSON的js包,json.js.json2.js.js ...
- SpringBoot Application深入学习
本节主要介绍SpringBoot Application类相关源码的深入学习. 主要包括: SpringBoot应用自定义启动配置 SpringBoot应用生命周期,以及在生命周期各个阶段自定义配置. ...
- ubantu删除源码安装文件
1.在安装目录下执行 make uninstall (如安装目录为/opt/software/opencv3.1.0/release) 2.删除系统相关文件 cd /usr sudo find . - ...
- htm&css 颜色的浮动
目标样式 目标分析: 由图可知,整个色板可以分为三块 可以理解为一个大的盒子包含了三个小的盒子,定义如下 LEFT的定义方式 TOP的定义方式 class为bottom的块最为复杂,但分析方法也是异曲 ...
- 开源WPF控件库MaterialDesignInXAML推荐
今天介绍一个开源的C# WPF开源控件库,非常漂亮,重点是开源哦 WPF做桌面开发是很有优势的,除了微软自带的控件外,还有很多第三方的控件库,比如收费的Dev Express For WPF.Tele ...
- vscode + platformIO开发stm32f4
我的电脑环境 win10 vscode 1.36.1 vscode安装插件 安装完这个插件后会提示你安装 platformIOCore,按照提示安装即可.安装过程可能比较缓慢, 可能需要翻墙. 新建项 ...
- 使用FastReport报表工具生成图片格式文档
之前我在随笔<使用FastReport报表工具生成报表PDF文档>介绍过使用FastReport.Net来根据报表模板进行生成PDF,以及随笔<使用FastReport报表工具生成标 ...