CF864D Make a Permutation!
思路:
贪心,构造,模拟。
实现:
#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!的更多相关文章
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
- [LeetCode] Palindrome Permutation 回文全排列
Given a string, determine if a permutation of the string could form a palindrome. For example," ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Next Permutation 下一个排列
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- 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 ...
- UVA11525 Permutation[康托展开 树状数组求第k小值]
UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ...
- 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 ...
- Permutation
(M) Permutations (M) Permutations II (M) Permutation Sequence (M) Palindrome Permutation II
随机推荐
- Google搜索引擎用法
Google搜索引擎用法 ★搜索引擎的选择 先简单说一下"搜索引擎的选择". 在咱们天朝,Google 屡屡被 GFW 骚扰,导致百度占了便宜,成为份额最高的搜索引擎.不过今天这篇 ...
- C#的DataGridView如何修改字体
在RowTemplate中可以修改字体和显示的格式(比如保留几位小数)
- datagrid行操作
//获取第一个被选中的行 var row=$('#dg').datagrid('getSelected'); //获取行对应的索引值 var index=$('#dg').datagrid('getR ...
- 怎样在win8系统下建立wifi热点
2012年10月26日,微软正式推出Windows 8操作系统,不少用户也都升级到了最新的Win8.大家知道.在Win7系统下,我们非常方便的就在命令提示符下建立了WIFI热点.那么Win8上是 ...
- java创建线程的三种方式及其对照
Java中创建线程主要有三种方式: 一.继承Thread类创建线程类 (1)定义Thread类的子类.并重写该类的run方法,该run方法的方法体就代表了线程要完毕的任务.因此把run()方法称为运行 ...
- BestCoder Round #56/hdu5463 Clarke and minecraft 水题
Clarke and minecraft 问题描述 克拉克是一名人格分裂患者.某一天,克拉克分裂成了一个游戏玩家,玩起了minecraft.渐渐地,克拉克建起了一座城堡. 有一天,克拉克为了让更多的人 ...
- URAL 1003,1004
1003: 并查集在处理矛盾关系的应用,讲的比较好的题解 #include <map> #include <set> #include <list> #includ ...
- 基于ASP.NET MVC的快速开发平台,给你的开发一个加速度!
基于ASP.NET MVC的快速开发平台,给你的开发一个加速度! bingo炸了 2017/4/6 11:07:21 阅读(37) 评论(0) 现在的人做事情都讲究效率,最好能达到事半功倍那种效果,软 ...
- springboot开发过程中的小坑(持续更新)
1. 启动的Application必须放到一个package下面,如下: package com.example.kikidemo; import org.springframework.boot.S ...
- 17年day3
/* 嗯,又一天. 时日无多了,还能蹦哒几天? 上午依旧考试,日常挂T1,读错题.还是好困. 兔子说明天晚上要请我们吃水饺~~~~去年就没这待遇. 下午打开邮箱一看,咦?嗯. 昨晚做噩梦NOIP考了状 ...