题目链接 http://codeforces.com/contest/740/problem/C
题意:有一串数字,给你m个区间求每一个区间内不含有的最小的数,输出全部中最小的那个尽量使得这个最小值最大,然后把符合条件的数字串输出,输出任意一种即可
这题只要理解题意差不多就能做出来了,很简单
由于题目要求的mex要最大(mex指着个区间中的数在0~n中缺少的最小的数字例如mex(1,2)=0,mex(0,2)=1,mex(0,1)=2)
所以尽量要从零开始递增,那么最小的mex值肯定是区间最小的那个,然后剩下的我们只要满足最小区间是从0开始的单调递增序列就可以了
其他区间靠取模来满足有一个简单的方法,就是1~n的数串赋值0~n-1然后模一下最小的mex即可,这样主要是为了满足得到最大的mex。
#include <iostream> #include <cstring> using namespace std; int main() { int n , m; cin >> n >> m; int MIN = 1e5 + 10; for(int i = 0 ; i < m ; i++) { int x , y; cin >> x >> y; MIN = min(MIN , y - x + 1); } cout << MIN << endl; for(int i = 0 ; i < n ; i++) { cout << i % MIN << ' '; } cout << endl; return 0; }