CF739A Alyona and mex 题解
前置知识
解法
从贪心的角度分析,最小的 \(\operatorname{mex}\) 仅会与长度最小的区间有关;另外为使得 \(\operatorname{mex}\) 最大,当 \(\operatorname{mex}\) 等于区间长度的时候即为所求。记 \(ans\) 表示此时得到的答案。
构造序列时,长度最小的区间一定包含 \([0,ans-1]\) 的所有数。对于其他的区间,一定包含一个长度为 \(ans\) 的区间,使得这个区间也包含 \([0,ans-1]\) 的所有数,剩余的部分长度如果小于 \(ans\),可以任意构造;否则,构造方法同上。于是,我们得到了一种可行的构造:将 \([0,ans-1]\) 循环输出即可。
代码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define sort stable_sort
#define endl '\n'
int main()
{
int n,m,l,r,i,len=0x7f7f7f7f;
cin>>n>>m;
for(i=1;i<=m;i++)
{
cin>>l>>r;
len=min(len,r-l+1);
}
cout<<len<<endl;
for(i=1;i<=n;i++)
{
cout<<i%len<<" ";
}
return 0;
}
CF739A Alyona and mex 题解的更多相关文章
- Codeforces Round #381 (Div. 2)C. Alyona and mex(思维)
C. Alyona and mex Problem Description: Alyona's mother wants to present an array of n non-negative i ...
- Codeforces Round #381 (Div. 1) A. Alyona and mex 构造
A. Alyona and mex 题目连接: http://codeforces.com/contest/739/problem/A Description Alyona's mother want ...
- CodeForces 682B Alyona and Mex (排序+离散化)
Alyona and Mex 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/B Description Someone gave ...
- Codeforces Round #358 (Div. 2) B. Alyona and Mex 水题
B. Alyona and Mex 题目连接: http://www.codeforces.com/contest/682/problem/B Description Someone gave Aly ...
- Codeforces 740C. Alyona and mex 思路模拟
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- Codeforces Round #358 (Div. 2)B. Alyona and Mex
B. Alyona and Mex time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Alyona and mex
Alyona and mex time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #381 (Div. 2)C Alyona and mex
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be ...
- 【39.66%】【codeforces 740C】Alyona and mex
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CF | Alyona and Mex
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyon ...
随机推荐
- OpenStack 工作流组件: Mistral
1 Mistral 简介 Mistral 是由 Mirantis 开发,贡献给 OpenStack 社区的工作流组件,它提供 Workflow As a Service 服务. 在计算机中通常处理的任 ...
- Java21 + SpringBoot3集成Spring Data JPA
.markdown-body { line-height: 1.75; font-weight: 400; font-size: 16px; overflow-x: hidden; color: rg ...
- 码农的转型之路-IoTBrowser(物联网浏览器)雏形上线
消失了半个月闭门造轮子去了,最近干了几件大事: 1.工控盒子,win10系统长时间跑物联网服务测试.运行快2周了,稳定性效果还满意,除了windows自动更新重启了一次. 2 .接触了一些新概念MQT ...
- Oracle ORA-01861: 文字与格式字符串不匹配(日期格式导致的问题)
1.问题 如图所示,Oracle ORA-01861: 文字与格式字符串不匹配.这里的日期格式出现问题,导致了ORA-01861错误. 2.解决方式 原因: 如果直接按照字符串方式,或者直接使用to_ ...
- Go-包-package-modules-import
- [转帖]Strong crypto defaults in RHEL 8 and deprecation of weak crypto algorithms
https://access.redhat.com/articles/3642912 TABLE OF CONTENTS What policies are provided? Removed c ...
- [转帖]如何使用coredump
一.coredump 当用户态进程出现异常后,在该进程的执行目录下生成对应的coredump文件,如果我们想将coredump生成的位置做改变,就需要如下设置. echo "/home/co ...
- [转帖]TiFlash 源码阅读(一) TiFlash 存储层概览
https://cloud.tencent.com/developer/article/1988629 背景 本系列会聚焦在 TiFlash 自身,读者需要有一些对 TiDB 基本的知识.可以通过这三 ...
- 【转帖】TCP内核参数
https://www.cnblogs.com/chia/p/7799231.html tcp_syn_retries :INTEGER默认值是5对于一个新建连接,内核要发送多少个 SYN 连接请求才 ...
- [转帖]【k8s】5、资源管理命令-声明式
文章目录 一. yaml和json介绍 1.yuml语言介绍 2.k8s支持的文件格式 3.yaml和json的主要区别 二.声明式对象管理 1.命令式对象配置 2.声明式对象配置 3.声明式对象管理 ...