hdu 6168 Numbers
Numbers
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 514 Accepted Submission(s): 270
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?
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]
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.
#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的更多相关文章
- HDU 6168 - Numbers | 2017 ZJUT Multi-University Training 9
/* HDU 6168 - Numbers [ 思维 ] | 2017 ZJUT Multi-University Training 9 题意: .... 分析: 全放入multiset 从小到大,慢 ...
- 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 ...
- HDU 5522 Numbers 暴力
Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5522 ...
- hdu 5585 Numbers
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5585 思路:对于2和5只须看最后一位数,对于三看所有位的数字之和就行 #include<stdi ...
- hdu 5585 Numbers【大数+同余定理】
Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- hdu 5181 numbers
http://acm.hdu.edu.cn/showproblem.php?pid=5181 题意: 有一个栈,其中有n个数1~n按顺序依次进入栈顶,在某个时刻弹出. 其中m个限制,形如数字A必须在数 ...
- HDU Humble Numbers
Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The ...
- HDU——1058Humble Numbers(找规律)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu 5181 numbers——思路+区间DP
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5181 题解:https://www.cnblogs.com/Miracevin/p/10960717.ht ...
随机推荐
- Linux文件目录介绍及文件颜色区别
文件颜色代表含义: 蓝色表示目录: 绿色表示可执行文件: 红色表示压缩文件: 浅蓝色表示链接文件: 白色表示其他文件: 黄色是设备文件,包括block, char, fifo. 常见目录解释 Linu ...
- [py][mx]django使用class写views-免去判断方法的烦恼
修改views使用class模式 类模式写views - 免去了函数模式的判断的烦恼 users/views.py from django.views.generic import View clas ...
- Cobbler 自动化部署系统
yum安装 yum install -y epel-release yum install -y httpd dhcp tftp cobbler cobbler-web pykickstart xin ...
- [LeetCode] 680. Valid Palindrome II_Easy tag: Two Pointers
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a pa ...
- Java的jdk1.6与jre1.8中存在的差异
一般来说: jdk每一个版本都是向后兼容的,说以低版本的代码是可以运行在高版本的虚拟机上的.而反过来则不可以,用1.6的编译器编辑的字节码文件是不可以运行在1.5版本的虚拟机上的. 但是今天我用Sun ...
- Makefile小结
Makefile最基本的规则:target....:prerequisites..... command 或:target....:prerequisites.....;command target: ...
- 209. Minimum Size Subarray Sum(双指针)
Given an array of n positive integers and a positive integer s, find the minimal length of a contigu ...
- Rpgmakermv(5) MiniLabel插件介绍
============================================================================ Introduction ========== ...
- VS2010/MFC编程入门之四十九(图形图像:CDC类及其屏幕绘图函数)
上一节中鸡啄米讲了文本输出的知识,本节的主要内容是CDC类及其屏幕绘图函数. CDC类简介 CDC类是一个设备上下文类. CDC类提供了用来处理显示器或打印机等设备上下文的成员函数,还有处理与窗口客户 ...
- Trove系列(五)—Trove的数据存储管理程序类型和版本管理功能介绍
功能描述数据存储管理程序(Datastore)类型管理允许Trove的用户从操作者列出的名单中选择数据库存储管理程序和版本.操作者将可以控制数据库存储管理程序的类型,添加一个新的版本并去活一个老版本. ...