Codeforces Round #315 (Div. 2) B 水题强行set
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 ≤ 105).
The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — 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.
题解:要求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的更多相关文章
- 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 ...
 - A. Yellow Cards (  Codeforces Round #585 (Div. 2) 思维水题
		
---恢复内容开始--- output standard output The final match of the Berland Football Cup has been held recent ...
 - 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 ...
 - Codeforces Round #315 (Div. 2) A 水且坑
		
A. Music time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
 - Codeforces Round #609 (Div. 2)前五题题解
		
Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...
 - Educational Codeforces Round 7 B. The Time 水题
		
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
 - Educational Codeforces Round 7 A. Infinite Sequence 水题
		
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
 - Codeforces Round #362 (Div. 2) A 水也挂
		
A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...
 - 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 ...
 
随机推荐
- Cobbler自动安装的Linux系统ssh无法进入
			
Linux ssh登陆老提示“permission denied,please try again” ,但是iptables已经关掉了 修改/etc/ssh/sshd_config文件.找如下的一句 ...
 - HTML第四章:初始css
			
CSS样式: 一.为什么要使用CSS;可以让页面更美观.有利于开发速度. 二.什么是CSS:全称cascading style shee ...
 - css中让元素隐藏的多种方法
			
{ display: none; /* 不占据空间,无法点击 / } { visibility: hidden; / 占据空间,无法点击 / } { position: absolute; top: ...
 - ZR#317.【18 提高 2】A(计算几何 二分)
			
题意 Sol 非常好的一道题,幸亏这场比赛我没打,不然我估计要死在这个题上qwq 到不是说有多难,关键是细节太多了,我和wcz口胡了一下我的思路,然后他写了一晚上没调出来qwq 解法挺套路的,先提出一 ...
 - 洛谷 3567/BZOJ 3524 Couriers
			
3524: [Poi2014]Couriers Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 2895 Solved: 1189[Submit][S ...
 - redis Connection refused 远程连接错误
			
redis 远程连接时报错: Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionE ...
 - MySQL的备份与恢复理解与备份策略
			
MySQL的备份主要分为逻辑备份和物理备份 逻辑备份 在MySQL中逻辑备份的最大优点是对各种存储引擎都可以用同样的方法来备份.而物理备份则不同,不同的存储引擎有着不同的备份方法.Mysql中的逻辑备 ...
 - 自动化运维工具——ansible剧本playbook(三)
			
一.Playbook--Ansible剧本 playbook是由一个或多个 "play"组成的列表 play的主要功能在于将事先归并为一组的主机装扮成事先通过ansible中的ta ...
 - Node.js 特点
			
1.单线程 在Java.PHP或者.net等服务器端语言中,会为每一个客户端连接创建一个新的线程.而每个线程需要耗费大约2MB内存.也就是说,理论上,一个8GB内存的服务器可以同时连接的最大用户数 ...
 - IP代理池之验证是否有效
			
IP代理池之验证是否有效 把proxy pool项目跑起来,但也不知道这些ip怎么用,爬虫的时候是否用代理去爬取,下面通过一个例子来看看. 代码如下: import requests PROXY_PO ...