思路:

贪心,构造,模拟。

实现:

 #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. MySQL主主复制搭建教程收集(待实践)

    先收集,后续再实践. http://www.cnblogs.com/ahaii/p/6307648.html http://blog.csdn.net/jenminzhang/article/deta ...

  2. JSP页面不支持EL表达式的解决方法

    JSP页面不支持EL表达式的问题就出在新建项目时web.xml的声明上. web.xml声明部分一般分为如下版本的xsd: web-app_2_2.xsd web-app_2_3.xsd web-ap ...

  3. php-7.1编译记录

    编译php-7.1.28步骤 检查环境 ./configure \ --prefix=/u01/server/php-7.1.28 \ --enable-fpm \ --with-fpm-user=d ...

  4. CentOS6 设置AliNetflow 环境

    CentOS6 设置AliNetflow 环境 Install OS 这一步略过. 只要保证操作系统是CentOS6.4 并且网络通畅 Install Python2.7.8 设置YUM 我的网络环境 ...

  5. Django打造大型企业官网(七)

    4.13.新闻列表tab栏布局完成 templates/news/index.html <div class="list-outer-group"> <ul cl ...

  6. HDMI信号解析

    参考资料:http://blog.sina.com.cn/s/blog_6cfd49b00102w00i.html: http://blog.csdn.net/gtkknd/article/detai ...

  7. 图像处理之基础---基于opencv的灰度图像微分

    argv分别为,可执行文件名.读入的原始图像.输出原始图像的灰度值.输出原始图像灰度值沿x轴方向的一阶微分.输出原始图像灰度值沿x轴方向的二阶微分. #include #include #includ ...

  8. Error处理: android.media.MediaRecorder.start(Native Method) 报错:start failed: -19【转】

    本文转载自:http://blog.csdn.net/netwalk/article/details/17686993 Error处理: android.media.MediaRecorder.sta ...

  9. [Codeforces 460C] Present

    [题目链接] https://codeforces.com/contest/460/problem/C [算法] 二分 + 贪心 要求最小值最大 , 我们不妨二分最小值 , 若一盆花的高度小于二分的值 ...

  10. 最长回文子串问题 O(n)算法 manacher URAL1297 HDU3068

    先来看一道简单的题,ural1297 给定一个1000长度的字符串,求最长回文子串. 看起来很Naive,乱搞一下,O(n^2)都可以解决. 再来看这个题 HDU3068 120个110000长度的字 ...