Codeforces Round #315 (Div. 2B) 569B Inventory 贪心
题目:Click here
题意:给你n,然后n个数,n个数中可能重复,可能不是1到n中的数。然后你用最少的改变数,让这个序列包含1到n所有数,并输出最后的序列。
分析:贪心。
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5+; int n;
int a[M]; // 给定序列
int mark[M]; // mark[i] 表示i在给定序列中的出现次数
int notap[M]; // 给的序列中没有出现的元素
bool firstout; void print( int x ) { // 输出格式控制 ps:在CF上测试了一下,不管这个格式也能AC
if( firstout ) {
printf("%d", x );
firstout = false;
}
else
printf(" %d", x );
} int main() {
while( ~scanf("%d", &n ) ) {
memset( mark, , sizeof(mark) );
memset( notap, , sizeof(notap) );
for( int i=; i<=n; i++ ) {
scanf("%d", a+i );
mark[a[i]]++;
}
int cnt = ;
for( int i=; i<=n; i++ )
if( !mark[i] ) {
notap[cnt] = i;
cnt++;
}
firstout = true;
int top = ;
for( int i=; i<=n; i++ )
if( mark[a[i]] == && a[i] <= n ) // 给定序列中有这个数并且范围合法
print( a[i] );
else {
print( notap[top] ); // 不然从没有的序列中弹出一个数
top++;
mark[a[i]]--;
}
printf("\n");
}
return ;
}
Codeforces Round #315 (Div. 2B) 569B Inventory 贪心的更多相关文章
- Codeforces Round #315 (Div. 2)【贪心/重排去掉大于n的元素和替换重复的元素】
B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #316 (Div. 2B) 570B Simple Game 贪心
题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int IN ...
- Codeforces Round #202 (Div. 1) A. Mafia 贪心
A. Mafia Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...
- Codeforces Round #382 (Div. 2)B. Urbanization 贪心
B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...
- Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp
题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...
- Codeforces Round #180 (Div. 2) B. Sail 贪心
B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...
- Codeforces Round #192 (Div. 1) A. Purification 贪心
A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...
- Codeforces Round #274 (Div. 1) A. Exams 贪心
A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...
- Codeforces Round #374 (Div. 2) B. Passwords 贪心
B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...
随机推荐
- Problem A: A + B
Problem A: A + BTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 17 Solved: 10[Submit][Status][Web Boar ...
- BZOJ 3479: [Usaco2014 Mar]Watering the Fields( MST )
MST...一开始没注意-1结果就WA了... ---------------------------------------------------------------------------- ...
- Servlet url-pattern优先级
完全匹配>目录匹配>扩展名匹配
- Android 开发笔记“context和getApplicationContext”
在android中常常会遇到与context有关的内容 浅论一下context : 在语句 AlertDialog.Builder builder = new AlertDialog.Builder( ...
- (Problem 70)Totient permutation
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...
- installscript类型 完成时实现推荐安装其他产品的功能
目前好多软件在安装完成时都有什么 立刻运行.打开网址.推荐安装其他工具等功能 我司领导也追时髦要求了这个功能而且要推荐多个,所以这个功能实现起来就需要自己去写代码了.陆陆续续研究了研究了好长时间,由于 ...
- HDU 1108 最小公倍数
#include <cstdio> int gcd(int a,int b) { ) return a; else return gcd(b,a%b); } int main() { in ...
- Sicily-1438
一. 题意 买二送一.排序之后隔三求和,求折扣的最大值. 二. 代码 // // main.cpp // sicily-1438 // // Created by ashley o ...
- poj 2153 Rank List(查找,Map)
题目链接:http://poj.org/problem?id=2153 思路分析: 判断Li Ming的成绩排名,需要在所有的数据章查找成绩比其高的人的数目,为查找问题. 查找问题可以使用Hash表, ...
- .Net将多个DLL打包为一个DLL(ILMerge)
在做.Net底层编码过程中,为了功能独立,有可能会生成多个DLL,引用时非常不便.这方面微软提供了一个ILMerge工具原版DOS工具,可以将多个DLL合并成一个.下载完成后需要安装一下,然后通过DO ...