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的更多相关文章
随机推荐
- Java 执行远程主机shell命令代码
pom文件: <dependency> <groupId>org.jvnet.hudson</groupId> <artifactId>ganymed- ...
- .net core 监听性能,异常
https://www.cnblogs.com/laozhang-is-phi/p/10287023.html#autoid-2-2-0
- Spring+SpringMVC+MyBatis+easyUI整合基础篇(一)项目简述及技术选型介绍
作者:13GitHub:https://github.com/ZHENFENG13版权声明:本文为原创文章,未经允许不得转载. 萌芽阶段 很久之前就开始打算整理一下自己的技术博客了,由于各种原因(借口 ...
- Windows Community Toolkit 4.0 - DataGrid - Part01
概述 在上面一篇 Windows Community Toolkit 4.0 - DataGrid - Overview 中,我们对 DataGrid 控件做了一个概览的介绍,今天开始我们会做进一步的 ...
- 使用 $(function(){}) 时遇到的一个小bug及解决方法
在 $(function(){}) 中声明函数,在 $(function(){}) 外调函数,会报错 原因: 页面加载后,会先执行 $(function(){}) 外面的语句,再执行 $(functi ...
- sql面试学到新内容
1.事物的保存点 MYSQL可以让我们对事务进行部分回滚,就是在事务里调用SAVEPOINT语句来设置一些命名标记.如果想要回滚到那个标记点位置,需要使用ROLLBACK语句来指定哪个保存点. mys ...
- PHP实用代码片段(四)
1. 删除文件夹内容 function Delete($path) { if (is_dir($path) === true) { $files = array_diff(scandir($path) ...
- rabbitmq集群运维一点总结
说明:以下操作都以三节点集群为例,机器名标记为机器A.机器B.机器C,如果为双节点忽略机器C,如果为各多节点则与机器C操作相同 一.rabbitmq集群必要条件 1.1.绑定实体ip,即ip a所能查 ...
- 优化MySQL性能的几种方法-总结
原文:http://bbs.landingbj.com/t-0-245601-1.html 1.要选取最适用的字段属性 MySQL可以很好的支持大数据量的存取,但是一般说来,数据库中的表越 小,在它上 ...
- html5-attr和prop
###1.什么是attrbute和property attribute(attr) html标签的预定义属性 checked html标签的自定义属性 a eg: <input ...