codeforces379a Alyona and mex

来源:互联网 发布:期权模拟交易软件 编辑:程序博客网 时间:2024/06/05 09:14

题意

给定一个n个数的序列和m个子序列,问没在m个子序列中出现过的可能的最大的数是多少(类似sg值),并输出任意一个符合要求的序列。

题目链接

思路

构造。。最大值取决于最短区间,只要保证最短区间是0 - len-1 即可,所以只要0-len-1循环即可。

代码

#include <stdio.h>#include <string.h>#include <queue>#include <algorithm>using namespace std;int n,m,a[101000];int main(){    scanf("%d%d",&n,&m);    int l,r;    int ans = 2e5;    for(int i = 1;i <= m;i ++){        scanf("%d%d",&l,&r);        ans = min(ans,r - l + 1);    }    int tmp = 0;    for(int i = 1;i <= n;i ++){        a[i] = tmp%ans;        tmp++;    }    printf("%d\n",ans);    for(int i =1;i <= n;i ++){        printf("%d%c",a[i],i == n?'\n':' ' );    }    return 0;}
0 0