B. Inventory
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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
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 
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.

题解:要求1~n的数字排列  若不满足,则更改尽量少的数字 使得满足1~n的任意排列

题意:随便搞   强行set处理 顺便再次熟悉一下set的方法  具体看代码

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#define ll __int64
#define mod 1000000007
#define PI acos(-1.0)
using namespace std;
set<int> s;
map<int,int>mp;
map<int,int>biao;
int main()
{
int n;
int exm;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
if(biao[i]==)
s.insert(i);
scanf("%d",&exm);
if(biao[exm]==&&exm>=&&exm<=n)
{
biao[exm]=;
mp[i]=exm;
if(s.count(exm)==)
s.erase(exm);
}
}
for(int i=;i<=n;i++)
{
if(mp[i])
{
cout<<mp[i]<<" ";
}
else
{
set<int>::iterator it = s.begin();
cout<<*it<<" ";
s.erase(*it);
}
}
return ;
}

最新文章

  1. select、poll、epoll之间的区别总结
  2. JS事件详解
  3. 在VS2010 下编译 cocos2d-x-2.1.4
  4. 数学软件 之 基于MATLAB的DFP算法
  5. 2016.9.14 JavaScript入门之七面向对象和函数
  6. preload pic
  7. Linux下GCC的使用
  8. 【Linux笔记】Linux目录结构
  9. Android之EditText组件学习
  10. Oracle查询优化改写--------------------单表查询
  11. 深入理解MyBatis框架的的配置信息
  12. 十五、过滤器(Filter)
  13. jsp页面如何读取从后台传来的json
  14. OC Foundation框架—结构体
  15. L5负载均衡
  16. 42. linux下数据库服务启动
  17. n=n+1 放在print(s)的上面的影响 (2) n=n=+1在前面,则不满足前面&lt;100条件时候,才跳出while的循环,这时候while循环结束, 到了外面的下一步--&gt;print()
  18. Homebrew1.5之后安装PHP和扩展
  19. 内网环境NTP服务及时间同步(CentOS6.x)配置和部署
  20. repcached与mysql缓存測试

热门文章

  1. Bootstrap历练实例:popover插件中的方法
  2. java算法面试题:编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串,但要保证汉字不被截取半个, 如“我ABC”,4,应该截取“我AB”,输入“我ABC汉DEF”,6,应该输出“我ABC”,而不是“我ABC+汉的半个”。
  3. Android驱动开发读书笔记七
  4. 定位设备--llseek实现
  5. 2018.10.30 NOIp模拟赛 T1 改造二叉树
  6. 详解----memcache服务端与客户端
  7. Shell脚本使用汇总整理——mysql数据库5.7.8以前备份脚本
  8. Nuxt.js 基础入门教程
  9. ES6 的解构赋值前每次都创建一个对象吗?会加重 GC 的负担吗?
  10. [USACO]玉米实验(单调队列)