【CodeForces - 569B】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

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开始,且保证充分利用之前的标记,输出最后每个物品的标记。 

给你t个数,合法的数为只出现在1~t之间,没有重复出现的数。要求你将不合法的数该为合法的数。

给你一组数据,其中有一些相同的或者大于n的数,要求你用1到n内的数替代,要求最后的数组内只能有1到n的数且无重复。

给出一个数字n,接下来是n个数,把其中的重复的数或者大于n的数进行替换,使得整个数列是由1~n来组成的,可能会有多种答案,输出其中任意一种。

解题报告:

   乱搞就可以了。对输入的数进行标记,一旦大于n或者重复出现,则标记一下,等待处理。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int a[MAX];
bool vis[MAX];
int ans[MAX];
int main()
{int n;cin>>n;memset(ans,-1,sizeof(ans));memset(vis,0,sizeof(vis));for(int i = 1 ; i <= n ; i++){cin >> a[i];if(!vis[a[i]] && a[i] <= n){ans[i] = a[i];vis[a[i]]=1;}}int cur = 1;for(int i = 1 ; i <= n ; i ++){if(ans[i] == -1){for(int j = cur; j<=n ; j++){if(!vis[j]){cur = j;ans[i] =cur;vis[cur]=1;cur++;break;}}}}for(int i = 1; i<=n ; i++) {printf("%d%c",ans[i],i == n ? '\n' : ' ');}return 0;	
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441504.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【CodeForces - 371D】Vessels(思维,元素合并,并查集)

题干&#xff1a; There is a system of n vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to n, in the order from the highest to the lowest, the volume of the i-th vessel is ai liters. Initially…

【UVA - 10891 Game of Sum 】【HRBUST - 1622】 Alice and Bob (区间dp,博弈问题)

题干&#xff1a; 有一个长度为N的整数序列&#xff0c;Alice和Bob轮流取数&#xff0c;Alice先取。每次玩家只能从左端或者右端 取一个或多个数&#xff0c;但不能两端都取。所有数都被取走后游戏结束&#xff0c;然后统计每个人取走的所有数之和&#xff0c; 作为各自的得分…

code iban 是有什么组成_EAN-128码和Code-128码的区别

什么是Code-128码&#xff1f;什么是EAN-128码&#xff1f;二者之间有什么区别&#xff1f;接下来小编就给大家解除心中的疑惑。Code-128码是一种高密度的条形码&#xff0c;可表示从 ASCII 0 到ASCII 127 共128个字符&#xff08;其中包含数字&#xff0c;字母&#xff0c;符号…

计算机中丢失setupxml.dll,Win7电脑安装VideoStudio Pro X6显示丢失SetupXML.dll文件怎么解决...

最近有win7系统用户在电脑安装VideoStudio Pro X6软件的时候&#xff0c;突然出现错误的提示&#xff0c;显示无法启动此程序&#xff0c;因为计算机中丢失SetupXML.dll。尝试重新安装该程序来解决此问题&#xff0c;要怎么办呢&#xff0c;下面给大家讲解一下Win7电脑安装软件…

怎么p出模糊的照片_36. 盲去卷积 - 更加实用的图像去模糊方法

本文同步发表在我的微信公众号和知乎专栏“计算摄影学”&#xff0c;欢迎扫码关注&#xff0c;上一篇文章35. 去卷积&#xff1a;怎么把模糊的图像变清晰&#xff1f;吸引了很多朋友的关注。在这篇文章里面&#xff0c;我给大家讲了一种叫做“非盲去卷积”的方法&#xff0c;当…

【CodeForces - 1038A 】Equality (思维水题,预处理字符串)

题干&#xff1a; You are given a string ss of length nn, which consists only of the first kk letters of the Latin alphabet. All letters in string ss are uppercase. A subsequence of string ss is a string that can be derived from ss by deleting some of its…

docker修改镜像的存储位置_云原生存储详解:容器存储与 K8s 存储卷(内含赠书福利)...

作者 | 阚俊宝 阿里巴巴技术专家参与文末留言互动&#xff0c;即有机会获得赠书福利&#xff01;导读&#xff1a;云原生存储详解系列文章将从云原生存储服务的概念、特点、需求、原理、使用及案例等方面&#xff0c;和大家一起探讨云原生存储技术新的机遇与挑战。本文为该系列…

vb简易计算机器程序,vb简易计算器源码

代码如下&#xff1a;/***Author:乌鸟heart*Version:1.0*/Dim IntX As Double 全局变量&#xff0c;用于存储计算的数值Dim IntOperation As Double 标记运算类型Dim isBegin As Boolean 标记是否已经给IntX赋值Public Sub Clear() 清空命令函数screen.Caption ""En…

【CodeForces - 1038B 】Non-Coprime Partition (构造,数组特征)

题干&#xff1a; Find out if it is possible to partition the first nn positive integers into two non-empty disjoint sets S1S1 and S2S2 such that: gcd(sum(S1),sum(S2))>1gcd(sum(S1),sum(S2))>1 Here sum(S)sum(S) denotes the sum of all elements presen…

计算机专业用锐龙笔记本,轻松应对工作挑战——ThinkPad T14 锐龙版,适合办公的笔记本电脑...

拥有一部适合办公的笔记本电脑&#xff0c;可以成为商务人士忙碌工作中强有力的支持。联想旗下的ThinkPad 系列笔记本电脑&#xff0c;一直秉持为高端商务人士服务的理念&#xff0c;以稳定、流畅、安全的使用体验得到广泛认可。其中的ThinkPad T14 锐龙版&#xff0c;更是有着…

python tabula 使用方法_Python中os.walk()的使用方法

os.walk()主要用来扫描某个指定目录下所包含的子目录和文件。这篇文章将通过几个简单的例子来说明python中os.walk()的使用方法。假设我们的test文件夹有如下的目录结构&#xff1a;我们首先用os.walk扫描test文件夹下所有的子目录和文件&#xff1a;# 使用os.walk扫描目录 imp…

【CodeForces - 1038C】Gambling (博弈问题,优先队列模拟,贪心)

题干&#xff1a; Two players A and B have a list of nn integers each. They both want to maximize the subtraction between their score and their opponents score. In one turn, a player can either add to his score any element from his list (assuming his list…

乐乐勇智能教育机器人有多少型号_【头条】协作机器人平台化趋势将会是柔性自动化的破局之道...

智能机器人商情微信公众号&#xff0c;关注中国智能机器人行业热点与发展趋势&#xff0c;打造快捷高效的行业资讯交互平台。更多精彩内容&#xff0c;您可以点击标题下方的蓝字关注我们。导语艾利特平台级CS系列协作机器人全新发布9月15日上海工博会第一天&#xff0c;艾利特机…

计算机毕设结束语致谢,毕业设计结束语和致谢

毕业设计结束语和致谢时间&#xff1a;2021-01-17 20:08:40 分类&#xff1a;小结范文 | 毕业论文致谢词范文 | Word文档下载毕业设计结束语和致谢导语&#xff1a;论文致谢应以简短的文字对课题研究与论文撰写过程中间直接给予帮助的人员(例如指导教师、答疑教师及其他人员)…

*【HDU - 2819】Swap(二分图匹配,输出路径)(待证明:是否是最少交换次数?)

题干&#xff1a; Given an N*N matrix with each entry equal to 0 or 1. You can swap any two rows or any two columns. Can you find a way to make all the diagonal entries equal to 1? Input There are several test cases in the input. The first line of each …

CSS中属性个属性值怎么区分,[CSS] 详细解释 @media 属性与 (max

前言现在 HTML5/CSS3 很流行罢&#xff0c;也是未来时代的趋势。在 HTML5 带来的许多实用功能之后&#xff0c;CSS3也同带来了一些牛逼哄哄的功能呢。动画 animation转化 transform过渡 translation尽快这已足够让我们兴奋&#xff0c;许多之前必须用 JS 或 JQ 写的效果用 CSS …

西门子精智和精简面板区别_西门子S7-1200的功能与特点,应用范围介绍

S7-1200是西门子公司新推出的一款面向离散自动化系统和独立自动化系统的低端PLC。S7-1200采用了模块化设计&#xff0c;具备强大的工艺功能&#xff0c;适用于多种场合&#xff0c;可以满足不同的自动化需求。S7-1200的定位处于原有的SIMATIC S7-200和SIMATIC S7-300之间&#…

【HDU - 1281 】棋盘游戏 (经典的二分图匹配,匈牙利算法,枚举删除顶点,必须边,关建边)

题干&#xff1a; 小希和Gardon在玩一个游戏&#xff1a;对一个N*M的棋盘&#xff0c;在格子里放尽量多的一些国际象棋里面的“车”&#xff0c;并且使得他们不能互相攻击&#xff0c;这当然很简单&#xff0c;但是Gardon限制了只有某些格子才可以放&#xff0c;小希还是很轻松…

eclipse提示方法已过时_提高效率,eclipse上你可能不知道的技巧

一张思维导图1、控制台(console )日志输出另保存经常会遇到这种情况&#xff0c;习惯性的清掉控制台上的输出日志&#xff0c;再然后发现刚才的日志居然还有用&#xff0c;不得不又重新调试一遍&#xff0c;为了解决这种“手贱”的问题&#xff0c;我在网上搜了一些资料&#x…

【CodeForces - 144B 】Meeting (暴力枚举,水题,计算几何)

题干&#xff1a; The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle…