#include<stdio.h> #include<string.h> int a[10001]; int main(int argc, char *argv[]) { int L,M; int start,end; while(~scanf("%d%d",&L,&M)) { memset(a,0,sizeof(a)); for(int i=0;i<M;++i) { scanf("%d%d",&start,&end); for(int i=start;i<=end;++i) a[i]=1; } int ans=0; for(int i=0;i<=L;++i) if(a[i]==0) ans++; printf("%d\n",ans); } return 0; }
原文:http://blog.csdn.net/wdkirchhoff/article/details/42241271