P1047 题解

题目简单

直接题解

#include<cstdio>
int a[10000];
int main(){
    int i,le,m,l,r,to,j;
    scanf("%d%d",&le,&m);
    to=le+1;
    for(i=1;i<=m;i++){
        scanf("%d%d",&l,&r);
        for(j=l;j<=r;j++)//关键在这里
            a[j]=1;
    }
    for(i=0;i<=le;i++)
        if(a[i])to--;
    printf("%d",to);
    return 0;
}

  

原文地址:https://www.cnblogs.com/wangshengjun/p/luoguP1047.html