(全国多校重现赛一) 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 16-矩形嵌套(贪心 + 动态规划DP)
16-矩形嵌套 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:13 submit:28 题目描述: 有n个矩形,每个矩形可以用a,b来描述,表示长和 ...
- Ubuntu Server16.04 安装Odoo11
odoo11采用了python3实现的. 1.sudo adduser odoo //新建一个用户odoo 2.给odoo 用户root 权限 visudo //使用visudo 编辑 /et ...
- [FPGA]Verilog实现可自定义的倒计时器(24秒为例)
目录 想说的话... 样例_边沿检测计数器 代码讲解 仿真演示 拓展_自定义倒计时数和倒计时间隔 代码讲解 仿真演示 总结 实例_24秒倒计时器 想说的话... 本次实现的是一个24秒倒计时器,功能顾 ...
- PostGIS 爆管分析之找出上游阀门
环境: Win10 ArcMap10.4(用于数据处理) postgresql9.4 postgis2.2.3 pgRouting2.3(postgresql插件) 说明: 继上一篇文章做了爆管分析找 ...
- PHP中Redis扩展无法加载问题
问题: 在重启php-fpm的过程中,发生了如下的错误,redis.so无法载入 1 2 3 4 [root@brand009 modules]# /usr/sbin/php-fpm /usr/sbi ...
- tomcat启动窗口出现乱码
tomcat启动窗口出现乱码 或者 idea运行服务器tomcat出现乱码 在tomcat的启动窗口打印的启动信息中包含了大量的中文乱码, 虽然这些对tomcat本身的使用没有任何影响,但却非 ...
- Gemini.Workflow 双子工作流高级教程:数据库设计及各表作用说明
整体数据库设计,可见这一篇:Gemini.Workflow 双子工作流高级教程:数据库-设计文档 这里对各数据表进行介绍: 工作流里的设计表并不多,核心只有以下8个: 下面按照流程的顺序来介绍一下表的 ...
- Python 信息提取-爬虫
import requests import re from bs4 import BeautifulSoup url = "http://python123.io/ws/demo.html ...
- 分布式存储Minio集群环境搭建
MinIO 分布式集群搭建 分布式 Minio 可以让你将多块硬盘(甚至在不同的机器上)组成一个对象存储服务.由于硬盘分布在不同的节点上,分布式 Minio 避免了单点故障. Minio 分布式模式可 ...
- [ch04-02] 用梯度下降法解决线性回归问题
系列博客,原文在笔者所维护的github上:https://aka.ms/beginnerAI, 点击star加星不要吝啬,星越多笔者越努力. 4.2 梯度下降法 有了上一节的最小二乘法做基准,我们这 ...