codeforces 569B B. Inventory(水题)
题目链接:
1 second
256 megabytes
standard input
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.
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.
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.
- 3
1 3 2
- 1 3 2
- 4
2 2 3 3
- 2 1 3 4
- 1
2
- 1
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(水题)的更多相关文章
- Codeforces Gym 100531G Grave 水题
Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...
- codeforces 706A A. Beru-taxi(水题)
题目链接: A. Beru-taxi 题意: 问那个taxi到他的时间最短,水题; AC代码: #include <iostream> #include <cstdio> #i ...
- Codeforces 489A SwapSort (水题)
A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- codeforces 688A A. Opponents(水题)
题目链接: A. Opponents time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CodeForces 534B Covered Path (水题)
题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...
- Codeforces Gym 100286I iSharp 水题
Problem I. iSharpTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- 【40.17%】【codeforces 569B】Inventory
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- CodeForces 705A(训练水题)
题目链接:http://codeforces.com/problemset/problem/705/A 从第三个输出中可看出规律, I hate that I love that I hate it ...
- CodeForces Gym 100685C Cinderella (水题)
题意:给定 n 个杯子,里面有不同体积的水,然后问你要把所有的杯子的水的体积都一样,至少要倒少多少个杯子. 析:既然最后都一样,那么先求平均数然后再数一下,哪个杯子的开始的体积就大于平均数,这是一定要 ...
随机推荐
- Javascript模式(二) 发布者/订阅者模式
var publisher = { // 订阅者数组 subscribers : { "any" : [] }, // 增加订阅者 on : function(type, fn, ...
- 26:IPMaskCheck识别有效的ip地址和掩码并分类统计
题目描述 请解析IP地址和对应的掩码,进行分类识别.要求按照A/B/C/D/E类地址归类,不合法的地址和掩码单独归类. 所有的IP地址划分为 A,B,C,D,E五类 A类地址1.0.0.0~126.2 ...
- centos-64整合nginx和tomcat
centos-64整合nginx和tomcat 分类: Linux 2013-04-25 10:41 128人阅读 评论(0) 收藏 举报 1.安装wget和依赖包 yum install wget ...
- 关于HDFS NFS3的配置
1.在core-site.xml中配置 <property> <name>hadoop.proxyuser.root.groups</name> <value ...
- hdu4612 无向图中随意加入一条边后使桥的数量最少 / 无向图缩点+求树的直径
题意如上,含有重边(重边的话,俩个点就能够构成了边双连通). 先缩点成树,在求数的直径,最远的连起来,剩下边(桥)的自然最少.这里学习了树的直径求法:第一次选随意起点U,进行bfs,到达最远的一个点v ...
- TP框架---thinkphp查询和添加数据
查询 <?php namespace Admin\Controller; use Think\Controller; class MainController extends Controlle ...
- 【转】soapUI和Jmeter的接口测试结构区别
使用SoapUI和Jmeter都可以进行自动化接口测试,但是每个工具都有自身的特点,所以他们的结构也有一定的区别 SoapUI 项目名称 -Rest服务.Rest资源 在使用SoapUI进行接口测试时 ...
- HIbernate 级联删除
在一对多的情形下如 Cinema - > Screen; 1.正常在不设置级联(casCade)的情况下 删除一的一方(Cinema)会报外键关联异常 (Screen 中包含Cinema的外键) ...
- 九度OJ 1166:迭代求立方根 (迭代)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3695 解决:1700 题目描述: 立方根的逼近迭代方程是 y(n+1) = y(n)*2/3 + x/(3*y(n)*y(n)),其中y0 ...
- 给this添加属性
const f =()=>{ console.log(this) let a=5 console.log(this) console.log(this) this.ak =3} f() let ...