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. Unity3D中使用Profiler精确定位性能热点的优化技巧

    本文由博主(SunboyL)原创,转载请注明出处:http://www.cnblogs.com/xsln/p/BeginProfiler.html 简介 在使用Profiler定位代码的性能热点时,很 ...

  2. Servlet----------用servlet写一个“网站访问量统计“的小案例

    package cn.example; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Ser ...

  3. mysql python pymysql模块 增删改查 查询 fetchone

    import pymysql mysql_host = '192.168.0.106' port = 3306 mysql_user = 'root' mysql_pwd = ' encoding = ...

  4. UVA 11136 Hoax or what (multiset)

    题目大意: 超时进行促销.把账单放入一个箱子里 每次拿取数额最大的和最小的,给出 最大-最小  的钱. 问n天总共要给出多少钱. 思路分析: multiset 上直接进行模拟 注意要使用long lo ...

  5. golang使用vet进行语法检查

    go tool vet是你的好朋友,不要忽视它. vet是一个优雅的工具,每个Go开发者都要知道并会使用它.它会做代码静态检查发现可能的bug或者可疑的构造.vet是Go tool套件的一部分,我们会 ...

  6. Spark DataFrame vector 类型存储到Hive表

    1. 软件版本 软件 版本 Spark 1.6.0 Hive 1.2.1 2. 场景描述 在使用Spark时,有时需要存储DataFrame数据到Hive表中,一般的存储方式如下: // 注册临时表 ...

  7. [vue]vue-book

    我们打算要做这几个模块 首页 列表 收藏 添加 home.vue --> list.vue -->app.vue --> main.js 安装环境 npm i vue-cli -g ...

  8. [py]django前台处理后端返回的各类数据

    参考 要完成的任务 返回str 返回list 返回arr 前端遍历 关键字 if for语句处理str list dict - 遍历字典 for语句 {% for key, value in info ...

  9. smali过滤特定字符串

    过滤插入代码: const-string/jumbo v0, "aaaaaaa" invoke-static {v0}, Lcom/bihu/insurancerobot/util ...

  10. div 在css中透明度怎么调?

    可以用这个属性:opacity: 0.95;opacity为属性,0.95为值(其中值的范围在0~1之间) 参考:https://zhidao.baidu.com/question/689118188 ...