codeforces569B
Inventory
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.
During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering.
You have been given information on current inventory numbers for n items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to n by changing the number of as few items as possible. Let us remind you that a set of n numbers forms a permutation if all the numbers are in the range from 1 to n, and no two numbers are equal.
Input
The first line contains a single integer n — the number of items (1 ≤ n ≤ 105).
The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — the initial inventory numbers of the items.
Output
Print n numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them.
Examples
3
1 3 2
1 3 2
4
2 2 3 3
2 1 3 4
1
2
1
Note
In the first test the numeration is already a permutation, so there is no need to change anything.
In the second test there are two pairs of equal numbers, in each pair you need to replace one number.
In the third test you need to replace 2 by 1, as the numbering should start from one.
sol:XJB乱构造,对于只出现一次的当然保留,否则替换成没出现过的,顺便把当前数字的出现次数-1
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,a[N],Ges[N],Shuz[N];
int main()
{
int i;
R(n);
for(i=;i<=n;i++)
{
Ges[a[i]=read()]++;
}
for(i=;i<=n;i++) if(!Ges[i]) Shuz[++*Shuz]=i;
int Now=;
for(i=;i<=n;i++)
{
if(a[i]<=n&&Ges[a[i]]==) W(a[i]);
else
{
W(Shuz[Now++]);
Ges[a[i]]--;
}
}
return ;
}
/*
input
3
1 3 2
output
1 3 2 input
4
2 2 3 3
output
2 1 3 4 input
1
2
output
1
*/
codeforces569B的更多相关文章
随机推荐
- The first day in cnblogs
2018.12.16,学习OI的第4个月零20天,我在博客园开通了属于自己的博客.
- 给ubuntu换内核
本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 下载内核源码 有两种方式,一种方式是直接从官网:https://www.kernel.org/直接下载,另一种方 ...
- keystone系列四:keystone部署及操作
一 前言 任何软件的部署都是没有技术含量的,任何就部署讲部署的人都是江湖骗子. 部署的本质就是拷贝,粘贴,回车.我们家养了条狗,它可以胜任这件事情. 我们搞技术的,一定不能迂腐:轻信或者一概不信. 轻 ...
- 从.Net框架Bug的提交到修复代码成功合并到.NET CoreFX主线
从发现.NET Framework中SmtpClient的Bug并拿出解决方案,然后给微软开发者社区提交Bug开始,总共耗时一个多月,对Bug修复的代码最终被采纳,现已合并到.NET Core Lib ...
- 性能调优8:分组聚合 - group by
聚合实际上对数据做分组统计,SQL Server使用两种操作符来实现聚合,流聚合(Stream Aggregation)和哈希聚合(Hash aggration).流聚合是非阻塞性的,具有流的特性,流 ...
- Xamarin.Forms 3.0的新特性
近期因为工作关系开始使用Xamarin,翻译了两篇国外的介绍3.0新特性的文章,供大家参考. 第一篇文章来自Xamarin官网,原文地址:https://blog.xamarin.com/xamari ...
- Redis系列文章总结:ASP.Net Core 中如何借助CSRedis实现一个安全高效的分布式锁
引言:最近回头看了看开发的.Net Core 2.1项目的复盘总结,其中在多处用到Redis实现的分布式锁,虽然在OnResultExecuting方法中做了防止死锁的处理,但在某些场景下还是会发生死 ...
- IIS6下使用多域名和通配符证书
由于SSL协议,在完成握手以前,都只能采用IP地址通信方式,没有办法获取访问地址中的域名信息,所以针对每个IP地址的每个端口,服务器只能返回相同的一张证书.如果要实现多个不同域名共享一个IP地址的缺省 ...
- python学习第十篇——while 的灵活运用
sandwiches_orders = ['apple','banana','mango',"apple","watermelon"] finished_san ...
- 使用 Travis CI 实现项目的持续测试反馈
[篇幅较长,10.15前补充完毕,如希望探索可直接移步Github仓库:https://github.com/SivilTaram/CITest] 在编程课中,我们可以使用成熟的在线评测系统来测试某个 ...