当前位置:网站首页>Codeforces 1629 C. Mexico array - simple greed
Codeforces 1629 C. Mexico array - simple greed
2022-06-12 13:32:00 【Tianyi City*】
The question :
Give you a length of n Array of a And an empty array b, You can choose the front at a time k individual , Find out the MEX, Plug into the b At the back of .
To make b The dictionary order is the largest , Ask what the answer is .
Answer key :
A lot about the dictionary order is greed , So since this problem needs the largest dictionary order , Then we must be greedy when we pick up , Then enumerate what each number is , And then look at the present a If you can find , If you can't find it, it's it .
At the same time, pay attention to maintenance a The number remaining in .
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N];
set<int>s[N];
vector<int>ans;
int main()
{
int t;
scanf("%d",&t);
while(t--){
ans.clear();
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]),s[a[i]].insert(i);
int l=1;
while(l<=n){
int mx=-1,i;
for(i=0;i<=n;i++){
if(s[i].empty())break;
mx=max(mx,*s[i].begin());
}
if(mx==-1){
s[a[l]].erase(s[a[l]].begin());
ans.push_back(0);
l++;
continue;
}
ans.push_back(i);
while(l<=mx)s[a[l]].erase(s[a[l]].begin()),l++;
}
printf("%d\n",ans.size());
for(int i:ans)
printf("%d ",i);
printf("\n");
}
return 0;
}
边栏推荐
- import torch_ Data view of geometric
- 【刷题篇】抽牌获胜的概率
- Redis message queue repeated consumption
- Volume mount and mirror creation
- The problem of Joseph in Informatics
- JVM runtime parameters
- 达梦数据库DM8 windows环境安装
- import torch_geometric 第一个图网络例子
- Multi source BFS problem template (with questions)
- Software construction 03 regular expression
猜你喜欢
![[EDA] chip layout design: VLSI layout design using electric](/img/a1/da0739070c940b36bc7a55d8eb2fe5.jpg)
[EDA] chip layout design: VLSI layout design using electric

It is enough to read this article. Web Chinese development

微信web开发者工具使用教程,web开发问题

创新实训(十)高级界面美化

618进入后半段,苹果占据高端市场,国产手机终于杀价竞争
![Will the next star of PPT for workplace speech be you [perfect summary] at the moment](/img/11/ac67db2641f42ef3d09417b790feb8.png)
Will the next star of PPT for workplace speech be you [perfect summary] at the moment

多源BFS问题 模板(附题)

Record some settings for visual studio 2019

Realization of Joseph Ring with one-way ring linked list

Multi source BFS problem template (with questions)
随机推荐
Qualcomm platform development series (Protocol) QMI brief introduction and usage
Automatic Generation of Visual-Textual Presentation Layout
Teach you how to create SSM project structure in idea
[EDA] chip layout design: VLSI layout design using electric
Informatics Olympiad all in one 2059: [example 3.11] buy a pen
Realization of Joseph Ring with one-way ring linked list
当字节跳动在美国输出中国式 996
"New continent" of mobile application going to sea
2063: [example 1.4] cattle eat grass
Title: Yanghui triangle
Hudi key generation
数据类型转换和条件控制语句
Application of short circuit expression (||) in C language
Seekg, tellg related file operations
C语言【23道】经典面试题【下】
安装MySQL时出错,照着下面这个链接,做到cmd就不行了
Installation of pagoda
TCP的“非”可靠性
Record some settings for visual studio 2019
Tinyxml Usage Summary