click here~~

                                      **B. 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. Sample test(s)
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

题目大意:就是有n个数。不能有比n大的数,然后尽可能的改变最少的步骤就能让它符合题意,注意a[i] >=1,当然不看也能够。

。。

解体思路:就是用两个数组,一个是标记的,另一个是将不符合的转化为符合的数。

详细详见代码:

/*
Date : 2015-8-20 Author : ITAK Motto : 今日的我要超越昨日的我,明日的我要胜过今日的我;
以创作出更好的代码为目标,不断地超越自己。
*/
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 1e5+5; bool f[maxn];//推断是不是符合条件
int data[maxn];
int fac[maxn];//把不符合的改为符合的除0外
int main()
{
int m;
scanf("%d",&m);
memset(f, 0, sizeof(f));
int cnt = 1;//记录不符合的个数。从1開始啊。。。 for(int i=1; i<=m; i++)
{
scanf("%d",&data[i]);
if(!f[data[i]] && data[i]<=m)
f[data[i]] = 1;
else
{
fac[cnt] = i;
cnt++;
}
}
cnt--;
for(int i=m; i>0; i--)
{
if(!f[i])
{
data[fac[cnt]] = i;
cnt--;
}
}
for(int i=1; i<m; i++)
printf("%d ",data[i]);
printf("%d\n",data[m]);
return 0;
}

Codeforces 569 B. Inventory的更多相关文章

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

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

  2. codeforces 569B B. Inventory(水题)

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

  3. CodeForces 569B Inventory 货物编号

    原题: http://codeforces.com/contest/569/problem/B 题目: Inventory time limit per test1 second memory lim ...

  4. Codeforces Round #569 题解

    Codeforces Round #569 题解 CF1179A Valeriy and Deque 有一个双端队列,每次取队首两个值,将较小值移动到队尾,较大值位置不变.多组询问求第\(m\)次操作 ...

  5. Codeforces Round #569 (Div. 2)A. Alex and a Rhombus

    A. Alex and a Rhombus 题目链接:http://codeforces.com/contest/1180/problem/A 题目: While playing with geome ...

  6. Codeforces Round #569 (Div. 2) C. Valeriy and Deque

    链接: https://codeforces.com/contest/1180/problem/C 题意: Recently, on the course of algorithms and data ...

  7. Codeforces Round #569 (Div. 2) B. Nick and Array

    链接: https://codeforces.com/contest/1180/problem/B 题意: Nick had received an awesome array of integers ...

  8. Codeforces Round #569 (Div. 2) 题解A - Alex and a Rhombus+B - Nick and Array+C - Valeriy and Dequ+D - Tolik and His Uncle

    A. Alex and a Rhombus time limit per test1 second memory limit per test256 megabytes inputstandard i ...

  9. Codeforces Round #315 (Div. 2B) 569B Inventory 贪心

    题目:Click here 题意:给你n,然后n个数,n个数中可能重复,可能不是1到n中的数.然后你用最少的改变数,让这个序列包含1到n所有数,并输出最后的序列. 分析:贪心. #include &l ...

随机推荐

  1. web结对项目

    一.Coding.Net项目地址:        https://git.coding.net/verde/Pair_Work.git 二.对接口进行的设计 看教科书和其它资料中关于Informati ...

  2. java8新特性lamda表达式在集合中的使用

    1.利用stream().forEach()循环处理List; List<String> list = Lists.newArrayList();//新建一个List 用的google提供 ...

  3. BZOJ 4551 [Tjoi2016&Heoi2016]树 ——并查集

    树剖显然可以做. 然而有一种更神奇的方法,并查集+时光倒流. 每个节点指向它上面最近的标记节点,标记节点指向自己,然后删除标记,就可以用并查集查询了. #include <map> #in ...

  4. BZOJ 4820 [Sdoi2017]硬币游戏 ——期望DP 高斯消元

    做法太神了,理解不了. 自己想到的是建出AC自动机然后建出矩阵然后求逆计算,感觉可以过$40%$ 用一个状态$N$表示任意一个位置没有匹配成功的概率和. 每种匹配不成功的情况都是等价的. 然后我们强制 ...

  5. JDBC链接mysql,时间时0000-00-00 00:00:00时报错

    应为mysql默认最小timestamp是0001-01-01 00:00:00,所以查询出来会报错 需要加在链接的url中加入 &zeroDateTimeBehavior=convertTo ...

  6. CodeForces 618D Hamiltonian Spanning Tree

    题意:要把所有的节点都访问一次,并且不能重复访问,有两种方式访问,一种是根据树上的路径 走和当前节点连接的下一个节点cost x, 或者可以不走树上边,直接跳到不与当前节点连接的节点,cost y 分 ...

  7. poj 1981 Circle and Points

    Circle and Points Time Limit: 5000MS   Memory Limit: 30000K Total Submissions: 8131   Accepted: 2899 ...

  8. 【HDOJ2196】Computer(树的直径,树形DP)

    题意:给定一棵N个点树,询问这个树里面每个点到树上其他点的最大距离. n<=10000 思路:设f[u,1],f[u,2]为以U为根向下的最长与次长,g[u,1],g[u,2]为从哪个儿子转移来 ...

  9. 转 Python爬虫实战二之爬取百度贴吧帖子

    静觅 » Python爬虫实战二之爬取百度贴吧帖子 大家好,上次我们实验了爬取了糗事百科的段子,那么这次我们来尝试一下爬取百度贴吧的帖子.与上一篇不同的是,这次我们需要用到文件的相关操作. 本篇目标 ...

  10. linux信号-------初涉

    一.信号的本质 软中断信号(signal,又简称为信号)用来通知进程发生了异步事件.在软件层次上是对中断机制的一种模拟,在原理上,一个进程收到一个信号与处理器收到一个中断请求可以说是一样的.信号是进程 ...