当前位置:网站首页>Codeforces Global Round 21 B. NIT Destroys the Universe
Codeforces Global Round 21 B. NIT Destroys the Universe
2022-07-15 19:32:00 【追烽】
https://codeforces.com/contest/1696/problem/B
st=10:39, ed=11:16
标签
数组操作
题意
定义 mex(S) 为不在 S 中出现的最小非负整数.
给定长度为 n 的数组 a, 一次操作如下:
选择任意 [l,r], 使 w = mex(a[l -> r]), 然后使 a[l -> r] = w.
输出最小操作数, 使数组 a 全部为零.
思路
如果 a[l->r] 中没有 0, 那么可以使它变为 0.
最终目标是使所有 a[i] 变为 0, 所以只有使 w = 0 是有效操作.
以 0 为间隔点, 可以依次将区间变为 0 , 统计这些没有 0 的区间的个数即可.
如果 a[l->r] 中有 0, 那么可以使它变为非 0, 然后再进行 1 次操作变为 0.
所以至多需要进行 2 次操作.
将删除线部分所统计的区间个数与 2 比较, 输出最小值即可.
代码

#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
signed main(){
cin.tie(0)->sync_with_stdio(0);
int T;cin>>T;
while(T--){
int n,pre=0,x,ans=0;
cin>>n;
FOR(i,1,n){
cin>>x;
if(pre==0 and x!=0) ans++;
pre=x;
}
cout<<min(ans,2)<<'\n';
}
return 0;
}
边栏推荐
- Analysis of quantum secure communication
- exness:原油止跌反弹,晚间关注美国恐怖数据表现
- Codeforces Global Round 21 D. Permutation Graph
- 开机按F11 选择 one-shot再选U盘启动
- 网络地址转换
- Ubuntu 22.04 LTS 是目前最安全的版本的七大原因
- 易基因|ENCODE组蛋白ChIP-seq和转录因子ChIP-seq数据标准及处理流程
- C writes the database connection mode to the configuration file
- Is it safe for Huatai Securities to open an account online and what materials are needed
- 一键生成VR全景图展示
猜你喜欢
随机推荐
User login and registration function with verification code
ACL 2022 | 基于阅读理解的论点对抽取
How to deploy polardb for PostgreSQL?
【MT2126】 数字游戏
用户登录和注册功能带验证码
Win10定时运行程序
WTK6900H语音识别单芯片实现智能语音识别蓝牙耳机方案设计
HybridCLR——划时代的Unity原生C#热更新技术
安装CUDA失败的情况nsight visual studio edition失败
apache配置
kingbaseES V8R6集群备份恢复案例之---备库作为repo主机执行物理备份
好玩的ping命令
Research on Key Technologies of asset detection in Cyberspace
迪赛智慧数——柱状图(正负条形图):2022届毕业生不同城市的期望&实际薪资
Accumulate class hour experience and practice of children's programming
SQL也能玩转AI ?没错!MLOps Meetup V3 回顾|OpenMLBD+SQLFlow+Byzer
VS2019+CUDA11.1新建项目里没有CUDA选项
如何部署PolarDB for PostgreSQL?
Codeforces Round #802 B. Palindromic Numbers
请教一个问题, FLinkCDC同步mysql的数据,必须要root权限吗?









