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的更多相关文章
随机推荐
- docker学习(1)--基础概念
转载请注明源文章出处:http://www.cnblogs.com/lighten/p/6841677.html 1.前言 docker的官网:这里.下一段摘自官网描述. docker是世界领先的软件 ...
- JavaScript原生秒表、计时器
可以开始.暂停.清除. 效果图: 下面贴代码: <!DOCTYPE html> <html lang="en"> <head> <meta ...
- Java中的并发工具类(CountDownLatch、CyclicBarrier、Semaphore、Exchanger)
在JDK的并发包里提供了很多有意思的并发工具类.CountDownLatch.CyclicBarrier和Semaphore 工具类提供了一种并发流程控制的手段,Exchanger 工具类则提供了在线 ...
- python第八章:多任务--小白博客
多线程threading 多线程特点: #线程的并发是利用cpu上下文的切换(是并发,不是并行)#多线程执行的顺序是无序的#多线程共享全局变量#线程是继承在进程里的,没有进程就没有线程#GIL全局解释 ...
- windows安装Redis和客户端
一.Windows安装Redis 1.下载安装包Redis-x64-3.0.504.zip到本地 2.解压 3.打开CMD,切换到解压后的redis目录,然后 C:\Users\Administrat ...
- HDU - 1542 扫描线入门+线段树离散化
扫描线算法+线段树维护简介: 像这种求面积的并集的题目,就适合用扫描线算法解决,具体来说就是这样 类似这种给出点的矩形的对角的点的坐标,然后求出所有矩形面积的交集的问题,可以采用扫描线算法解决.图如下 ...
- Python—randonm模块介绍
random是python产生伪随机数的模块 >>> random.randrange(1,10) #返回1-10之间的一个随机数,不包括10 >>> random ...
- 01-HTML介绍
1.WEB标准 web准备介绍: w3c:万维网联盟组织,用来制定web标准的机构(组织) web标准:制作网页遵循的规范 web准备规范的分类:结构标准.表现标准.行为标准. 结构:html.表示: ...
- c++入门之字符相关入门
先上代码: # include "iostream" # include "string" //# define BYTE char//注意,这里没有分号,且# ...
- Python学习第十八篇——低耦合函数设计思想
import json 2 def greet_user(filename): 3 try: 4 with open(filename) as f_obj: 5 username = json.loa ...