题目链接:

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 ≤ 10^5).

The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 10^5) — 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.

题意:

把n个数变成1到n这n个数输出,就是把原来重复的和大于n的去掉,补上1到n中没有出现过的;

思路:

水题,直接不想说;

AC代码:

/*2014300227    569B - 26    GNU C++11    Accepted    46 ms    1196 KB*/
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+;
typedef long long ll;
const double PI=acos(-1.0);
int n,a[N],vis[N];
queue<int>qu;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
vis[a[i]]++;
}
for(int i=;i<=n;i++)
{
if(!vis[i])qu.push(i);
}
for(int i=;i<=n;i++)
{
if(a[i]>n)printf("%d ",qu.front()),qu.pop();
else {
if(vis[a[i]]==)printf("%d ",a[i]);
else if(vis[a[i]]>)
{
printf("%d ",qu.front());
qu.pop();
vis[a[i]]--;
}
}
} return ;
}

codeforces 569B B. Inventory(水题)的更多相关文章

  1. Codeforces Gym 100531G Grave 水题

    Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...

  2. codeforces 706A A. Beru-taxi(水题)

    题目链接: A. Beru-taxi 题意: 问那个taxi到他的时间最短,水题; AC代码: #include <iostream> #include <cstdio> #i ...

  3. Codeforces 489A SwapSort (水题)

    A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  4. codeforces 688A A. Opponents(水题)

    题目链接: A. Opponents time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. CodeForces 534B Covered Path (水题)

    题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...

  6. Codeforces Gym 100286I iSharp 水题

    Problem I. iSharpTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  7. 【40.17%】【codeforces 569B】Inventory

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. CodeForces 705A(训练水题)

    题目链接:http://codeforces.com/problemset/problem/705/A 从第三个输出中可看出规律, I hate that I love that I hate it ...

  9. CodeForces Gym 100685C Cinderella (水题)

    题意:给定 n 个杯子,里面有不同体积的水,然后问你要把所有的杯子的水的体积都一样,至少要倒少多少个杯子. 析:既然最后都一样,那么先求平均数然后再数一下,哪个杯子的开始的体积就大于平均数,这是一定要 ...

随机推荐

  1. C#比較对象的相等性

    对于相等的机制全部不同,这取决于比較的是引用类型还是值类型.以下分别介绍引用类型和值类型的相等性. 1.比較引用类型的相等性 System.Object定义了三种不同的方法,来比較对象的相等性:Ref ...

  2. C#按指定长度分割字符串

    C#按指定长度分割字符串   这几天学习分析声音的波形数据,接收到的是十六进制的数据,需要将数据转换成十进制再绘图,这个过程涉及到字符串的分割,正好可以促进自己对C#相关知识的学习.说到分割字符串,我 ...

  3. phpdoctor 安装,配置,生成文档

    window 下安装phpdoctor 1 安装php,设置环境变量path ,把php 的安装路径加上,比如php 安装在d:/php5/ 2下载phpdoctor,可以去官网下载 http://p ...

  4. Spring学习八----------Bean的配置之Resources

    © 版权声明:本文为博主原创文章,转载请注明出处 Resources 针对于资源文件的统一接口 -UrlResource:URL对应的资源,根据一个URL地址即可创建 -ClassPathResour ...

  5. android开发系列之ContentObserver

    在这篇博客里面我想要分享一下自己最近在项目里面遇到一个比较好的数据同步解决方案,首先让我们先来看看该方案的应用场景:我们在客户端本地利用数据库缓存了一些数据,当我们检测到数据库里面的数据发生变化的时候 ...

  6. java中 ExecutorService,Executor,ThreadPoolExecutor的用法

    package com; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Executor; import ...

  7. java中异或加密

    static String simple_xor(String base_data, String encrypt_key) throws UnsupportedEncodingException { ...

  8. 在dev目录创建一个字符设备驱动的流程

    1.struct file_operations 字符设备文件接口 1: static int mpu_open(struct inode *inode, struct file *file) 2: ...

  9. golang截取字符串

    对于字符串操作,截取字符串是一个常用的, 而当你需要截取字符串中的一部分时,可以使用像截取数组某部分那样来操作,示例代码如下: package main import "fmt" ...

  10. 可展开的UITableView (附源码)

    本文转载至 http://www.apkbus.com/forum.php?mod=viewthread&tid=137207&extra=page%3D1 由于工作需要,写了一个UI ...