思路:

贪心,构造,模拟。

实现:

 #include <bits/stdc++.h>
using namespace std;
int t[], a[], vis[], n;
int main()
{
while (cin >> n)
{
memset(t, , sizeof t); memset(vis, , sizeof vis);
int cnt = ;
for (int i = ; i < n; i++)
{
cin >> a[i]; t[a[i]]++;
if (t[a[i]] > ) cnt++;
}
cout << cnt << endl;
queue<int> q;
for (int i = ; i <= n; i++) if (!t[i]) q.push(i);
for (int i = ; i < n; i++)
{
if (!t[a[i]]) continue;
else if (t[a[i]] == && !vis[a[i]])
{
cout << a[i] << " "; t[a[i]]--;
}
else
{
if (vis[a[i]])
{
cout << q.front() << " "; q.pop();
}
else if (q.front() < a[i])
{
cout << q.front() << " "; q.pop();
}
else
{
cout << a[i] << " "; vis[a[i]] = ;
}
t[a[i]]--;
}
}
cout << endl;
}
return ;
}

CF864D Make a Permutation!的更多相关文章

  1. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  2. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  3. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  4. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Next Permutation 下一个排列

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  6. Leetcode 60. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  7. UVA11525 Permutation[康托展开 树状数组求第k小值]

    UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ...

  8. Permutation test: p, CI, CI of P 置换检验相关统计量的计算

    For research purpose, I've read a lot materials on permutation test issue. Here is a summary. Should ...

  9. Permutation

    (M) Permutations (M) Permutations II (M) Permutation Sequence (M) Palindrome Permutation II

随机推荐

  1. Postgis经常使用函数

    1,基本操作函数 AddGeometryColumn(<schema_name>, <table_name>,<column_name>, <srid> ...

  2. CI 知识 :Git介绍及常用操作

    Git介绍 Git(读音为/gɪt/.)是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本管理. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发 ...

  3. 开源 免费 java CMS - FreeCMS2.1 会员3.9我的收藏

    项目地址:http://www.freeteam.cn/ 我的收藏 从左側管理菜单点击我的收藏进入.在这里能够查看当前登录会员的全部收藏记录. 查看收藏 点击标题能够查看收藏内容. 删除收藏 选择收藏 ...

  4. android XXXActivity和getApplicationContext()差别

    从接触android起,到处都能看到context(上下文)的身影,查看源代码之后你会发现,它仅仅是个抽象类,详细实现都在ContextWrapper实现. 当你去查看android的源代码时,你会发 ...

  5. 【bzoj2464】中山市选[2009]小明的游戏

    直接转换成最短路 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstr ...

  6. curl HTTP_USER_AGENT

    [root@bigdata-server-01 ~]# curl 13.26.92.20array(27) { ["HTTP_USER_AGENT"]=> string(11 ...

  7. YTU 2630: E2 驾驭const

    2630: E2 驾驭const 时间限制: 1 Sec  内存限制: 128 MB 提交: 673  解决: 491 题目描述 引入了const关键词,用于指定"常"对象及&qu ...

  8. sublime —— 强大的插件

    1. 代码 自动补全与智能提示: All Autocomplete:Sublime Text 默认的 Autocomplete 功能只考虑当前的文件,而 All Autocomplete 插件会搜索所 ...

  9. bzoj3295 洛谷P3157、1393 动态逆序对——树套树

    题目:bzoj3295 https://www.lydsy.com/JudgeOnline/problem.php?id=3295 洛谷 P3157(同一道题) https://www.luogu.o ...

  10. Win7 64 位 vs2012 pthread 配置

    1.      首先下载pthread,解压后我放在了e盘. 2.      然后用vs2012新建一个工程,然后右键项目属性,在配置属性->VC++目录->包含目录中输入E:\pthre ...