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 ;
}

Codeforces Round #315 (Div. 2) B 水题强行set的更多相关文章

  1. Codeforces Round #336 (Div. 2)-608A.水题 608B.前缀和

    A题和B题...   A. Saitama Destroys Hotel time limit per test 1 second memory limit per test 256 megabyte ...

  2. A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题

    ---恢复内容开始--- output standard output The final match of the Berland Football Cup has been held recent ...

  3. Codeforces Round #345(Div. 2)-651A.水题 651B.。。。 651C.去重操作 真是让人头大

    A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. Codeforces Round #315 (Div. 2) A 水且坑

    A. Music time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  5. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  6. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  7. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  8. Codeforces Round #362 (Div. 2) A 水也挂

    A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...

  9. Codeforces Round #365 (Div. 2) A 水

    A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...

随机推荐

  1. jstree前端设置默认选中项

    $("#jstree").on("loaded.jstree", function (event, data) { var currDeptId = crm.g ...

  2. Angular 2 树节点的上下移动问题

    最近在做一个树节点的上下移动然后实现排序的问题.直接看图: 实现已选查询条件的上下移动.结合了primeng 的picklist 组件. 下面是html代码 <p-tabPanel header ...

  3. JQuery模拟点击页面上的所有a标签,触发onclick事件

    注意: 这种方法需要给所有的a标签加上id属性 页面加载完成模拟点击所有的a标签: <script> $(function () { // 模拟点击页面上的所有a标签,触发onclick事 ...

  4. 高级字符驱动之堵塞与非堵塞IO

    /** *此实例涉及到线程的挂起与竞态,字符IO的堵塞与非堵塞 */ struct scull_pipe { wait_queue_head_t inp, outp; char *buffer, *e ...

  5. 3170: [Tjoi2013]松鼠聚会

    Time Limit: 10 Sec  Memory Limit: 128 MB Submit: 1804  Solved: 968[Submit][Status][Discuss] Descript ...

  6. LAMP PHP 详解

    目录 LAMP PHP 详解 LAMP 请求流程与原理 PHP 简介 PHP Zend Engine Opcode php 配置详解 php 加速器 部署LAMP 使用 php 连接 mysql 最基 ...

  7. pymysql模块操作数据库及连接报错解决方法

    import pymysql sql = "select host,user,password from user" #想要执行的MySQL语句 #sql = 'create da ...

  8. 分享自己写的基于Dapper的轻量级ORM框架~

    1.说明 本项目是一个使用.NET Standard 2.0开发的,基于 Dapper 的轻量级 ORM 框架,包含基本的CRUD以及根据表达式进行一些操作的方法,目前只针对单表,不包含多表连接操作. ...

  9. linux正则表达式企业级深度实践案例2

    [root@redhat~]#  sed  -nr  ' s#([ ^ : ]+)  (: .* :)  (/.*$)#\3\2\1#gp '  /etc/passwd

  10. BootStrap下拉框搜索功能

    <!DOCTYPE html> <html> <head> <title>jQuery bootstrap-select可搜索多选下拉列表插件-www. ...