(全国多校重现赛一) 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最喜欢做的题型是数列大题,并且每一道都能得到满分. 你可能不相信,但其实他发现了一个结论:只要是数列,无论是给了通项还是给了递推式,无论定义多复杂,都可以被搞成等差数列.这样,只要 ...
随机推荐
- (Codeforce)The number of positions
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say ...
- Python OpenCV4趣味应用系列(四)---颜色物体实时检测
今天,我们来实现一个视频实时检测颜色物体的小实例,视频中主要有三个颜色物体,我们只检测红色和绿色的球状物体,如下图所示: 第一步需要打开视频(或者摄像头): cap = cv2.VideoCaptur ...
- T-SQL Part IX, PIVOT and UNPIVOT
不同于CROSS JOIN, CROSS APPLY, OUTER APPLY,MSDN文档对PIVOT和UNPIVOT 想得重视了一点,单独做了一个页面来介绍. 简单来说,PIVOT用来把行转成列, ...
- SpringBoot 源码解析 (五)----- Spring Boot的核心能力 - 自动配置源码解析
在上一篇博客中分析了springBoot启动流程,大体的轮廓只是冰山一角.今天就来看一下springBoot的亮点功能:自动化装配功能. 先从@SpringBootApplication开始.在启动流 ...
- Zabbix-(五)监控Docker容器与自定义jvm监控项
Zabbix-(五)监控Docker容器与自定义jvm监控项 一.前言 前文中讲述了Zabbix对服务器硬件方面的监控功能,本文将讲述利用Zabbix监控Docker容器中的Java Web服务,并通 ...
- nyoj 65-另一种阶乘问题 (Java 高精度)
65-另一种阶乘问题 内存限制:64MB 时间限制:3000ms 特判: No 通过数:16 提交数:18 难度:1 题目描述: 大家都知道阶乘这个概念,举个简单的例子:5!=1*2*3*4*5.现在 ...
- ZeroC ICE的远程调用框架 代理引用地址
在官方文档中称为Binding,协议-地址对的绑定.在Proxy模式中,一般地有三个参与者,Proxy,Subject以及RealSubject.Subject定义了Proxy(代理)和RealSub ...
- vue 父子组件传值,兄弟组件传值
父子组件中的传值 父向子 v-bind props <!-- 组件使用v-bind传值 --> <router :msg="msg"></rou ...
- 【NOIP2017】【Luogu P3956】【SPFA】棋盘
Luogu P3956 本题是一道简单的SPFA 具体看程序 #include<iostream> #include<cstdio> using namespace std; ...
- TensorFlow2.0极简安装(亲测有效)
x相信每一个学习深度学习的人来说都知道Google的深度学习框架TensorFlow,估计每个人都想成为一个TF Boy(TensorFlow Boy).我也是这个想法,于是我踏上了安装TensorF ...