Codeforces 739A Alyona and mex(构造)
来源:互联网 发布:练文笔的软件 编辑:程序博客网 时间:2024/05/22 13:36
Alyona's mother wants to present an array of n non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects m of its subarrays. Subarray is a set of some subsequent elements of the array. The i-th subarray is described with two integers li and ri, and its elements are a[li], a[li + 1], ..., a[ri].
Alyona is going to find mex for each of the chosen subarrays. Among these m mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.
You are to find an array a of n elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.
The mex of a set S is a minimum possible non-negative integer that is not in S.
The first line contains two integers n and m (1 ≤ n, m ≤ 105).
The next m lines contain information about the subarrays chosen by Alyona. The i-th of these lines contains two integers li and ri(1 ≤ li ≤ ri ≤ n), that describe the subarray a[li], a[li + 1], ..., a[ri].
In the first line print single integer — the maximum possible minimum mex.
In the second line print n integers — the array a. All the elements in a should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in a are between 0 and 109.
If there are multiple solutions, print any of them.
5 31 32 54 5
21 0 2 1 0
4 21 42 4
35 2 0 1
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5)is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
题意:mex(l,r)表示不存在于a[l],a[l+1],a[l+2],......,a[r]的集合中的最小非负整数。给出m个集合,需要构造数列使得m个mex中的最小的mex最大,先输出最大的mex,然后输出这个序列。
题解:血妈蹦(╯‵□′)╯︵┻━┻哭瞎,A敲错了字母,锁上之后才发现。C看得迷迷糊糊的,一直没搞清楚意思。以为最大的最小mex可以任意值呢,原来就是这m个区间中的最短区间长度 。假设最短区间长度为len,只有当区间为(0,1,2,......,len-1)的时候才可以使得mex为len,否则都会出现比len小的数。 明白这一点构造数列就简单多了,我们直接将序列循环构造成0,1,2,...len-1,0,1,2...len-1,0,1....这样的序列就可以了。 因为这样所有大于最小区间的区间里面都会至少拥有一次(0,1,2,...,len-1),都不会比最大的最小mex值小。
总结:还是太弱了,不能从题目信息里很快明白题目内涵,导致怀疑自己题都没看懂,要不断涨姿势啊,QAQ
代码如下:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){int n,m;while(scanf("%d%d",&n,&m)!=EOF){int ans=1e5+10,l,r;while(m--){scanf("%d%d",&l,&r);ans=min(ans,r-l+1); }printf("%d\n",ans);int cnt=0;printf("%d",cnt);cnt++;cnt%=ans;for(int i=2;i<=n;++i){printf(" %d",cnt);cnt++; cnt%=ans;}printf("\n");} return 0;}
- Codeforces 739A Alyona and mex(构造)
- CodeForces 740C Alyona and mex 简单构造题
- Codeforces Round #381 (Div. 1) A. Alyona and mex
- Codeforces 358 . B Alyona and Mex
- CodeForces 682B Alyona and Mex
- CodeForces 682B Alyona and Mex
- Codeforces Round #381C. Alyona and mex
- 【39.66%】【codeforces 740C】Alyona and mex
- Codeforces #381 C. Alyona and mex
- CodeForces 740C - Alyona and mex(思维)
- 740C.Alyona and mex codeforces
- CodeForces 682B Alyona and Mex
- Codeforces Round #381 (Div. 2)C. Alyona and mex(构造题,好题)
- Codeforces Round #381 (Div. 2) C. Alyona and mex 贪心+构造
- Codeforces Round #381 (Div. 2) C Alyona and mex (构造)
- codeforces 739b Alyona and a tree
- CODEFORCES 739B Alyona and a tree
- Alyona and Mex
- AJAX函数的封装
- ajax实例代码及效果
- [C++]LeetCode #1 twoSum
- ajax的应用原理及基本用法
- Leetcode 366. Find Leaves of Binary Tree (Medium) (cpp)
- Codeforces 739A Alyona and mex(构造)
- C++vector的使用方法
- 【20.23%】【codeforces 740A】Alyona and copybooks
- 【81.82%】【codeforces 740B】Alyona and flowers
- Leetcode 255. Verify Preorder Sequence in Binary Search Tree (Medium) (cpp)
- Redis 发布订阅简测
- ASP中实现文件上传方法的研究
- C++改善_2016_11_23
- 【39.66%】【codeforces 740C】Alyona and mex