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数组的内容
 
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = +;
  4. map<int,int>mp;
  5. int s[maxn];//记录a和b
  6. int t[maxn];//存储a数组的结果
  7.  
  8. void init()
  9. {
  10. mp.clear();
  11. memset(t,,sizeof(t));
  12. }
  13.  
  14. int main()
  15. {
  16. int n;
  17. while(~scanf("%d",&n) )
  18. {
  19. init();
  20. for(int i=;i<=n;i++)
  21. scanf("%d",&s[i]);
  22. sort(s+,s+n+);
  23. int tot = ;
  24. for(int i=;i<=n;i++)
  25. {
  26. if(tot + (tot-)*tot/ >= n)//总数够了 就不需要再选下去了
  27. break;
  28. int x= s[i];
  29. if(mp[x]== || mp.count(x)==)//前面是这个数在mp中 且数值为1 另外一个是这个不在mp中
  30. {
  31. for(int j=;j<tot;j++)
  32. {
  33. mp[x+t[j]]++;//把新挑出来的数和之前的都相加
  34. }
  35. t[tot++] = x;//存储这个数
  36. }
  37. else
  38. {
  39. mp[x]--;//这个数之前出现过 所以不需要加了
  40. }
  41. }
  42. cout<<tot<<endl;
  43. for(int i=;i<tot;i++)
  44. {
  45. if(i)
  46. cout<<" ";
  47. cout<<t[i];
  48. }
  49. cout<<endl;
  50. }
  51. return ;
  52. }

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. php 中date显示时间不对与Linux文件乱码问题

    php 中date显示时间不对解决办法如下1.修改/etc/php.ini文件 在里头中找到data.timezone =去掉它前面的分号';' 然后设置data.timezone = “Asia/S ...

  2. 通过phantomjs 进行页面截图

    本文章参考了使用phantomjs操作DOM并对页面进行截图需要注意的几个问题 及phantomjs使用说明 这两篇文章,初次接触phantomjs的童鞋可以去看下这两篇原文 在学习中可以看下 pha ...

  3. EL--Expression Language

    EL 存取变量数据的方法很简单,例如:${username}.它的意思是取出某一范围中名称为username的变量.因为我们并没有指定哪一个 范围的username,所以它的默认值会先从Page 范围 ...

  4. [django]Django model中数据批量导入bulk_create()

    参考: https://www.cnblogs.com/ccorz/p/Django-model-zhong-shu-ju-pi-liang-dao-rubulkcreat.html import o ...

  5. weka数据挖掘拾遗(一)---- 生成Arff格式文件

    一.什么是arff格式文件 1.arff是Attribute-Relation File Format缩写,从英文字面也能大概看出什么意思.它是weka数据挖掘开源程序使用的一种文件模式.由于weka ...

  6. 4.keras实现-->生成式深度学习之DeepDream

    DeepDream是一种艺术性的图像修改技术,它用到了卷积神经网络学到的表示,DeepDream由Google于2015年发布.这个算法与卷积神经网络过滤器可视化技术几乎相同,都是反向运行一个卷积神经 ...

  7. java多态性方法的重写Overriding和重载Overloading详解

    java多态性方法的重写Overriding和重载Overloading详解 方法的重写Overriding和重载Overloading是Java多态性的不同表现.重写Overriding是父类与子类 ...

  8. Fortran入门:Windows平台的Fortran编译器安装和使用

    因为课程需要,今年开始学习FORTRAN语言.之前学校的计算概论用的是C,后来又学了C++和Python作为面向对象的工具,数值计算方面主要通过学校的许可证用的MATLAB.因为专业侧重数值模拟和反演 ...

  9. C语言常用函数大全

    一.数学函数 调用数学函数时,要求在源文件中包下以下命令行: #include <math.h> 函数原型说明 功能 返回值 说明 int abs( int x) 求整数x的绝对值 计算结 ...

  10. mysql查询表基本操作

    数据库表的创建create table <表名>( <列名> <数据类型及长度> [not null], <列名> <数据类型及长度>, . ...