2017 ACM暑期多校联合训练 - Team 9 1008 HDU 6168 Numbers (模拟)
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?
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 ai 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). 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
题意:
已知数组a由n也元素组成,数字b由数组a里面的任意两个元素相加组成,则数组b里面的元素个数为n(n-1)/2.
现在a数组和b数组混合在一起一共有m个元素,求解a数组里面的元素个数,并将这些元素打印出来。
分析:
首先可以确定的是,混合数组里面的两个最小的元素一定是a数组里面的值,这样每次将找到的值与a数组中已有的值相加得到的值从混合数组里面删去,这样混合数组中现存的第一个值肯定就是要加入到a数组里面的,接着重复进行上面的过程,直到找齐a数组里面的元素。
其实就是个存粹的模拟的过程。
代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4;
typedef long long ll;
ll a[maxn];
int main()
{
ll num, m;
while(~scanf("%lld", &m))
{
map <ll, ll> M;
ll min1=1000000009,min2=1000000000;///数列中的次小值和最小值
ll n=(sqrt(8*m+1)-1)/2;///根据n与m的关系,列出n的表达式
for(ll i=0; i<m; i++)
{
scanf("%lld",&num);
if(num<min2)///如果比最小值还小,两个值都要更新
{
min1=min2;
min2=num;
}
else if(num<min1)///比次小值小,只更新次小值就行了
{
min1=num;
}
M[num]++;
}
M[min1] --;
M[min2] --;
a[0] = min2;
a[1] = min1;
ll ans = 1;
while(ans != n - 1)
{
for(ll i = 0; i < ans; ++ i)
{
M[a[i] + a[ans]] --;
}
map<ll, ll>::iterator it = M.begin();
while(it!= M.end())///找到map容器里面第一个非0 的元素
{
if(it -> second == ll(0))
{
M.erase(it ++);
}
else
{
break;
}
}
a[++ ans] = M.begin() -> first;///这个值肯定是a里面的一个元素
M[a[ans]] --;
}
printf("%lld\n",n);
printf("%lld",a[0]);
for(int i=1; i<n; i++)
printf("% lld",a[i]);
printf("\n");
}
return 0;
}
2017 ACM暑期多校联合训练 - Team 9 1008 HDU 6168 Numbers (模拟)的更多相关文章
- 2017 ACM暑期多校联合训练 - Team 5 1008 HDU 6092 Rikka with Subset (找规律)
题目链接 Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, s ...
- 2017 ACM暑期多校联合训练 - Team 3 1008 HDU 6063 RXD and math (莫比乌斯函数)
题目链接 Problem Description RXD is a good mathematician. One day he wants to calculate: ∑i=1nkμ2(i)×⌊nk ...
- 2017 ACM暑期多校联合训练 - Team 4 1007 HDU 6073 Matching In Multiplication (模拟)
题目链接 Problem Description In the mathematical discipline of graph theory, a bipartite graph is a grap ...
- 2017 ACM暑期多校联合训练 - Team 4 1012 HDU 6078 Wavel Sequence (模拟)
题目链接 Problem Description Have you ever seen the wave? It's a wonderful view of nature. Little Q is a ...
- 2017ACM暑期多校联合训练 - Team 8 1008 HDU 6140 Hybrid Crystals (模拟)
题目链接 Problem Description Kyber crystals, also called the living crystal or simply the kyber, and kno ...
- 2017ACM暑期多校联合训练 - Team 7 1008 HDU 6127 Hard challenge (极角排序)
题目链接 Problem Description There are n points on the plane, and the ith points has a value vali, and i ...
- 2017ACM暑期多校联合训练 - Team 6 1008 HDU 6103 Kirinriki (模拟 尺取法)
题目链接 Problem Description We define the distance of two strings A and B with same length n is disA,B= ...
- 2017ACM暑期多校联合训练 - Team 2 1008 HDU 6052 To my boyfriend (数学 模拟)
题目链接 Problem Description Dear Liao I never forget the moment I met with you. You carefully asked me: ...
- 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)
题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...
随机推荐
- python 安装pymssql
error: command 'gcc' failed with exit status 1 ---------------------------------------- Command &quo ...
- 检测web服务器指定位置大文件是否存在
在bugscan群里看到有人问有一个大文件,想探测其是否存在.如果使用curl的话,会将整个文件下载到节点,对于扫描没有任何用处,反而浪费了扫描时间. 于是我想到的解决办法是不使用curl,直接用底层 ...
- (暂时弃坑)ACM数论之旅15---置换群与Polya定理(我把标题看成poi了,poipoipoi(*≧▽≦)ツ)
(挖坑...) ////////////////////////////////////////////////// 暂时弃坑 开学了,有空再写....
- APP 测试 与 WEB 测试的本质区别
单纯从功能测试的层面上来讲的话,APP 测试.web 测试 在流程和功能测试上是没有区别的 根据两者载体不一样,则区别如下: 1.系统结构方面 web项目,b/s架构,基于浏览器的:web测试只要更新 ...
- SPOJ_VLATTICE
题目是给你一个空间,和一个点(n,n,n),求从原点出发能够直接接触多少个点(不经过任何一个点)? 典型的mobius反演即可. 首先,ans=3,因为(1,0,0),(0,1,0),(0,0,1)这 ...
- Java pdf转String 并修正格式
在尝试pdf转成String的时候,首先用python的pdfminer和pdfminer3k去尝试转换,然后资料看不太懂,就尝试用了java, 以下是java的pdfbox写的pdf转String函 ...
- BZOJ 3295 动态逆序对 | CDQ分治
BZOJ 3295 动态逆序对 这道题和三维偏序很类似.某个元素加入后产生的贡献 = time更小.pos更小.val更大的元素个数 + time更小.pos更大.val更小的元素个数. 分别用类似C ...
- Alpha 冲刺 —— 十分之八
队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭鸭鸭鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 多次测试软件运行 学习OPENMP ...
- USACO Section 2.1 Ordered Fractions 解题报告
题目 题目描述 给定一个数N(1<=N<=160),需要产生所有的分数,这些分数的值必须要在0~1之间.而且每个分数的分母不能超过N.如下例所示: N = 5 产生所有的分数:0/1 1/ ...
- 【ARC083E】Bichrome Tree
Description 给一棵\(n\)个节点的树,和一个长度同样为\(n\)的非负整数序列\(x_i\). 请尝试对每个节点染黑或白两种颜色,并确定一个非负整数权值. 问是否存在一种方案 ...