CodeForces - 740C
这题是思维考察。由于区间个数可能会很多,暴力完全没法下手。首先要明确区间长度最小的就决定了最后的答案,因为最小区间必须要要从0开始到区间长度减1才能满足让mex最大。接下来就是考虑如何填充数组才能让所有区间的mex大于等于最小区间的mex,暴力根本没法下手,我是直接考虑最短区间,比他更长的区间如果覆盖了比它更短的区间那么更长区间的mex一定大于等于短区间的mex,直接让数组所有的长度为最短区间长度的区间的mex成为最大最小mex,就可以得到答案了。
AC代码:
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e5+5;
const int inf=1<<30;
int res[maxn];
int main(){
int n,m,cnt;
while(scanf("%d%d",&n,&m)!=EOF){
cnt=inf;
int x,y;
for(int i=0;i<m;++i){
scanf("%d%d",&x,&y);
cnt=min(cnt,y-x+1); //计算最短区间长度
}
for(int i=0;i<n;++i){
res[i]=i%cnt; //填充数组
}
printf("%d\n",cnt);
for(int i=0;i<n;++i){
if(i==n-1) printf("%d\n",res[i]);
else printf("%d ",res[i]);
}
}
return 0;
}
其实数组完全可以省略。
如有不当之处欢迎指出!
CodeForces - 740C的更多相关文章
- Codeforces 740C. Alyona and mex 思路模拟
C. Alyona and mex time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...
- 【39.66%】【codeforces 740C】Alyona and mex
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces 740C Alyona and mex
构造. 比较骚的构造题.肯定可以构造出$min(R-L+1)$,只要$0$ $1$ $2$ $...$ $R-L$ $0$ $1$ $2$ $...$ $R-L$填数字即可,这样任意一段区间都包含了$ ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- JavaScript事件高级绑定
js 进行事件绑定,其中一种不常见的写法是: <div id="father" style="width: 300px; height: 200px; backgr ...
- maven系列--eclipse的m2插件
工欲善其事,必先利其器.我是讨厌用CMD指令来操作maven,既然eclipse已经给我们提供了插件,那我们为什么不使用呢?而且我觉得eclipse的各种插件都挺好用的.好了废话不多说了,现在开始整理 ...
- getResource()和getSystemResource()分析
1. getClass().getResource() 第一步,getClass().getResource(path)是有一个路径参数的,这个路径会先被转换成"类所在的包名称+path&q ...
- Android 使用EventBus发送消息接收消息
基本使用 自定义一个类 public class LoginEvent { private String code;//是否成功 public LoginEvent(String code) { th ...
- find与tar的结合使用
新建一个文件,自定义时间点[root@nhserver2 ~]# touch -t 1403010000.00 file1.txt 新建一个文件,自定义时间点[root@nhserver2 ~]# ...
- Codeforce A. Fair Game
A. Fair Game time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- 18_Python列表常用方法总结
''' 1.列表切片索引\截取 2.列表的增删改查 3.列表最大值\列表最小值\排序 4.列表的遍历 5.列表的嵌套 6.列表和字符串的互转 7.判断元素是否在列表中 ''' #列表使用中括号表示 元 ...
- ABP官方文档翻译 6.1.2 MVC视图
ASP.NET MVC 视图 介绍 AbpWebViewPage基类 介绍 ABP通过Abp.Web.Mvc nuget包集成到MVC视图.你可以如往常一样创建正常的MVC视图. AbpWebView ...
- 洛谷 [P2764]最小路径覆盖问题
二分图应用模版 #include <iostream> #include <cstdio> #include <algorithm> #include <cs ...
- HDU [1529] || POJ [P1275] Cashier Employment
经典的差分约束+二分答案. 本题的难点在于如何建图. 设x[i] 表示第i个小时可以开始工作的有多少个人. num[i] 表示第i个小时最少需雇佣多少人. s[i] 表示1...i小时实际开始工作的有 ...