【40.17%】【codeforces 569B】Inventory
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
【题目链接】:http://codeforces.com/contest/569/problem/B
【题解】
for 扫一遍,把没出现的数字记录下来;
for 扫一遍,把每个数字出现的次数记录下来;
for 扫一遍,如果该数字出现次数大于1,则随便把它改成一个没出现的数字;
或者该数字大于n也要改成一个没出现的数字;
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int MAXN = 1e5+10;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
int n;
int a[MAXN];
map <int,int> dic;
vector <int> g;
int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(n);
rep1(i,1,n)
{
rei(a[i]);
dic[a[i]]++;
}
rep1(i,1,n)
if (dic[i]==0)
g.pb(i);
int len = g.size();
len--;
rep1(i,1,n)
{
int temp = dic[a[i]];
if (a[i]>n)
{
a[i] = g[len];
len--;
}
else
if (temp>1)
{
dic[a[i]]--;
a[i] = g[len];
len--;
}
}
rep1(i,1,n)
{
printf("%d",a[i]);
if (i==n) puts("");
else
printf(" ");
}
return 0;
}
【40.17%】【codeforces 569B】Inventory的更多相关文章
- JAVA 基础编程练习题17 【程序 17 猴子吃桃问题】
17 [程序 17 猴子吃桃问题] 题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个 第二天早上又 将剩下的桃子吃掉一半,又多吃了一个.以后每天早上都吃了前一天剩下的一 ...
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- codeforces 569B B. Inventory(水题)
题目链接: B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 【24.17%】【codeforces 721D】Maxim and Array
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【47.40%】【codeforces 743B】Chloe and the sequence
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【17.07%】【codeforces 583D】Once Again...
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【27.40%】【codeforces 599D】Spongebob and Squares
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces】【比赛题解】#855 Codefest 17
神秘比赛,以<哈利波特>为主题……有点难. C题我熬夜切终于是写出来了,可惜比赛结束了,气啊. 比赛链接:点我. [A]汤姆·里德尔的日记 题意: 哈利波特正在摧毁神秘人的分灵体(魂器). ...
- 【codeforces 514D】R2D2 and Droid Army
[题目链接]:http://codeforces.com/contest/514/problem/D [题意] 给你每个机器人的m种属性p1..pm 然后r2d2每次可以选择m种属性中的一种,进行一次 ...
随机推荐
- jQuery UI:邮箱自动补全函数
$('#email').autocomplete({ delay:0, autoFocus:true, source:function(request,response){ var hosts = [ ...
- 2018-8-10 模拟赛T3(可持久化线段树)
出题人说:正解离线按DFS序排序线段维护区间和 但是对于树上每个点都有一个区间和一个值,两个点之间求1~m的区间和,这不就是用可持久化线段树吗. 只不过这个线段树需要区间修改,不过不需要标记下传,询问 ...
- ArcGIS小技巧——提取面要素的质心点
如下图,现在要做这样一件事,提取面图层中每一个图斑的质心点,然后使用质心点提取图层中的一个属性值,并在此基础上进行克里金插值,生成该属性的空间插值图.当然,今天这段文字主要简单说一下怎样提取面图层的质 ...
- MFC CListctr显示缩略图
我们知道通过CImageList可以让listctr显示出图片,但是添加的图片大小必须和要CImageList 创建的图片大小一致,才能显示出来.最近遇到一个需求,需要把很多大小不一的jpeg图片通过 ...
- 基于EmguCV的摄像机标定及矫正
标签: EmguCV摄像头标定C# 2015-05-03 14:55 501人阅读 评论(6) 收藏 举报 分类: C# 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] ...
- 驱动学习3-make
在向内核中添加驱动的时候要完成3项工作 (1)在Kconfig中添加新代码对应项目的编译条件(下面Makefile文件中需要用到它定义的的宏变量) (2)将驱动源码添加到对应的目录中 (3)在目录Ma ...
- Spring Boot 热部署(转)
Spring Boot 热部署 实际开发中,修改某个页面数据或逻辑功能都需要重启应用.这无形中降低了开发效率,所以使用热部署是十分必要的. 什么是热部署? 应用启动后会把编译好的Class文件加载的虚 ...
- Android, IOS 史上最强多语言国际化,不仅第一次会尾随系统,并且会保存用户的语言设置
劲爆消息,我提供源代码了.你能够先看完再下载.也能够先下载再看完, android源代码地址: https://github.com/hebiao6446/------Bluetooth-Androi ...
- amazeui页面分析5
amazeui页面分析5 一.总结 1.把原模板当成样例集合就好 2.都是一块一块的,删改等操作都方便 3.list方面的操作很多都是ui配合li 4.其实容器本质还是div,所以真的算简单了 5.样 ...
- GMTC2019会后:做一场冷门的技术专场是什么体验
上周四(6.20)GMTC2019大会的第一天,很荣幸作为「UI与图形渲染」专场出品人获得了与图形领域几位技术专家同场交流的机会. 图形技术在前端范畴内是一个相对小众的话题,虽然前端工程师几乎每天都在 ...