思路:

贪心,构造,模拟。

实现:

 #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. JDBC的Statement对象

    以下内容引用自http://wiki.jikexueyuan.com/project/jdbc/statements.html: 一旦获得了数据库的连接,就可以和数据库进行交互.JDBC的Statem ...

  2. 我的arcgis培训照片13

    来自:http://www.cioiot.com/successview-535-1.html

  3. SD卡 驱动层测速

    init_timer(&timer1); timer1.function = test_time; timer1.data = ; timer1.expires = jiffies + mse ...

  4. 集成学习(ensemble method)--基于树模型

    bagging方法(自举汇聚法 bootstrap aggregating) boosting分类:最流行的是AdaBoost(adaptive boosting) 随机森林(random fores ...

  5. 在HDInsight中从Hadoop的兼容BLOB存储查询大数据的分析

    在HDInsight中从Hadoop的兼容BLOB存储查询大数据的分析 低成本的Blob存储是一个强大的.通用的Hadoop兼容Azure存储解决方式无缝集成HDInsight.通过Hadoop分布式 ...

  6. Dll,OCX控件的注册(转)

    原文地址:http://home.51.com/heiyijiushi/diary/item/10053693.html C#自动实现Dll(OCX)控件注册的两种方法2012-07-31 21:20 ...

  7. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] B. Finding Team Member 排序

                                                                      B. Finding Team Member             ...

  8. MySQL InnoDB 快速导入数据

    今天把需要分析的数据导入到数据库中. 数据将近7000万条,在txt文件中存放,共5.75G.采用Load data infile 导入,最后花了18个小时导入.主要做了以下修改: 1. MySQL优 ...

  9. Bootstrap button源码分析

    /* ======================================================================== * Bootstrap: button.js v ...

  10. 8-23 canvas专题

    8-23 canvas专题-了解外部框架的使用 学习要点 掌握画布内容的导出的toDataURL()方法 了解外部框架的使用 第八章内容介绍 在第八章中我们将对以前的知识进行简单的回顾,着重对canv ...