Numbers

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 514    Accepted Submission(s): 270

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.
 
题意 已经有an个数 对于 1≤i<j≤n,an中的数 两两相加,得到b数组  然后把a,b数组乱序  让你挑选出a数组的内容
 
#include<bits/stdc++.h>
using namespace std;
const int maxn = +;
map<int,int>mp;
int s[maxn];//记录a和b
int t[maxn];//存储a数组的结果 void init()
{
mp.clear();
memset(t,,sizeof(t));
} int main()
{
int n;
while(~scanf("%d",&n) )
{
init();
for(int i=;i<=n;i++)
scanf("%d",&s[i]);
sort(s+,s+n+);
int tot = ;
for(int i=;i<=n;i++)
{
if(tot + (tot-)*tot/ >= n)//总数够了 就不需要再选下去了
break;
int x= s[i];
if(mp[x]== || mp.count(x)==)//前面是这个数在mp中 且数值为1 另外一个是这个不在mp中
{
for(int j=;j<tot;j++)
{
mp[x+t[j]]++;//把新挑出来的数和之前的都相加
}
t[tot++] = x;//存储这个数
}
else
{
mp[x]--;//这个数之前出现过 所以不需要加了
}
}
cout<<tot<<endl;
for(int i=;i<tot;i++)
{
if(i)
cout<<" ";
cout<<t[i];
}
cout<<endl;
}
return ;
}

hdu 6168 Numbers的更多相关文章

  1. HDU 6168 - Numbers | 2017 ZJUT Multi-University Training 9

    /* HDU 6168 - Numbers [ 思维 ] | 2017 ZJUT Multi-University Training 9 题意: .... 分析: 全放入multiset 从小到大,慢 ...

  2. 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 gen ...

  3. HDU 5522 Numbers 暴力

    Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5522 ...

  4. hdu 5585 Numbers

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5585 思路:对于2和5只须看最后一位数,对于三看所有位的数字之和就行 #include<stdi ...

  5. hdu 5585 Numbers【大数+同余定理】

    Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  6. hdu 5181 numbers

    http://acm.hdu.edu.cn/showproblem.php?pid=5181 题意: 有一个栈,其中有n个数1~n按顺序依次进入栈顶,在某个时刻弹出. 其中m个限制,形如数字A必须在数 ...

  7. HDU Humble Numbers

    Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...

  8. HDU——1058Humble Numbers(找规律)

    Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  9. hdu 5181 numbers——思路+区间DP

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5181 题解:https://www.cnblogs.com/Miracevin/p/10960717.ht ...

随机推荐

  1. Integer VS AtomicInteger VS MutableInteger

    由于Integer是不可变的,每个循环增加key的value时会创建一个新的对象 每次value+1时不需要重新创建Integer对象 Integer, Boolean 等 is immutable, ...

  2. mac chrome 驱动配置

    将解压后的chromedriver移动到/usr/local/bin目录下

  3. java 泛型没有协变类型, 所以要重用extends, 但使用List<? extends Fruit> 可以是ArrayList<Fruit>()、ArrayList<Apple>()、ArrayList<Orange>(), 因此不能add元素进去

    class Fruit{} class Apple extends Fruit{} class SubApple extends Apple{} class Orange extends Fruit{ ...

  4. HDU5012:Dice(bfs模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 Problem Description There are 2 special dices on the ...

  5. PAT 1072 Gas Station[图论][难]

    1072 Gas Station (30)(30 分) A gas station has to be built at such a location that the minimum distan ...

  6. js 使用jquery.form.js文件上传

    1.文件上传,使用jquery.form.js插件库 <!DOCTYPE html> <html> <head> <meta charset="UT ...

  7. linux命令:linux权限管理命令

    权限管理命令   文件的权限只有你两个人可以更改,一个是root,一个是文件所有者. 命令名称:chmod 命令英文原意:change the permissions mode of a  file ...

  8. DIV CSS 绘制风车

    我得说,CSS和DIV是个有趣的东西. 由于脑袋一无聊,突然想,画个DIV风车怎么样,于是就画了一个. border的风格可以自主选择. 上代码: <style> *{ margin:0p ...

  9. MFC六大核心机制之四:永久保存(串行化)

    永久保存(串行化)是MFC的重要内容,可以用一句简明直白的话来形容其重要性:弄懂它以后,你就越来越像个程序员了! 如果我们的程序不需要永久保存,那几乎可以肯定是一个小玩儿.那怕我们的记事本.画图等小程 ...

  10. mysql性能优化1

    当我们去设计数据库表结构,对操作数据库时(尤其是查表时的SQL语句),我们都需要注意数据操作的性能.这里,我们不会讲过多的SQL语句的优化,而只是针对MySQL这一Web应用最多的数据库.希望下面的这 ...