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
随机推荐
- 解决Spring MVC无法接收AJAX使用PUT与DELETE请求传输的内容
解决Spring MVC无法接收AJAX使用PUT与DELETE请求传输的内容 解决方案 在 Web.xml文件中 加入以下代码 <!--解决ajax Put与Del请求无法接收到传输的内容-- ...
- pycharm下运行和调试scrapy项目
1. 新建项目 默认在本地已经新建了一个scrapy爬虫项目 2. 打开项目 点击open à 选择刚刚那个本地的scrapy项目meijutt100 3. 项目结构 各个py文件的作用不作介绍,不懂 ...
- Spring Boot实现多个数据源教程收集(待实践)
先收集,后续实践. http://blog.csdn.net/catoop/article/details/50575038 http://blog.csdn.net/neosmith/article ...
- 保持WCF服务端与客户端的长连接
背景 客户端与服务端使用WCF建立连接后:1.可能长时间不对话(调用服务操作):2.客户端的网络不稳定. 为服务端与客户端两边都写“心跳检测”代码?不愿意. 解决 设置inactivityTimeou ...
- 手动安装Firefox Linux
(2015-06-05 17:22:19)[编辑][删除] 转载▼ 标签: 股票 Firefox 下载文件以.tar和.bz2格式保存,必须从这些压缩包中提取文件.不想删除当前安装的 Firefox, ...
- js逻辑执行判断
两个变量或者函数,如果与的关系,a && b,如果a是真则在运行b,如果a是假则不运行b了:如果是或的关系,前者是真则不运行后边的了,否则反过来. 举个例子: <span cla ...
- USRP内部的寄存器
usrp_regs.hpp #ifndef INCLUDED_USRP2_REGS_HPP #define INCLUDED_USRP2_REGS_HPP ////////////////////// ...
- android菜鸟之路-事件分发机制总结(二)
ViewGroup事件分发机制 自己定义一个LinearLayout,ImageView和Button,小二,上代码 <LinearLayout xmlns:android="http ...
- ubuntu12.04通过Ganglia利用NVML模块进行GPU监控
1.安装Ganglia,这里安装的是3.1*版本,因为监控GPU的模块只支持3.1*版本系列的 apt-get install ganglia* 2.下载并安装PyNVML和NVML模块,下载地址ht ...
- 将mvvmlight 移植到 ios step1
https://github.com/wangrenzhu/SimpleIoc-For-Objective-c simple ios for objective-c 版 基本实现 全部功能 完美实现 ...