qianzhihexs @ 2024-10-15 15:28:24
#include <stdio.h>
int cha(int m,int n);
int main(void)
{int l,i,m,a,b;
scanf("%d %d",&l,&m);
int num[m-1];
for(i=0;i<=m-1;i++)
{scanf("%d %d",&a,&b);
num[i]=cha(a,b);
l=l-num[i];
}
printf("%d",l+1);
return 0;
}
int cha(int m,int n)
{int d;
if(m>n)
return m-n+1;
else
return n-m+1;
}
by ZYFERIC @ 2024-10-19 17:22:37
#include <stdio.h>
int main(){
int a[10005]={},l,m,c,d,sum=0;
scanf("%d%d",&l,&m);
while(m--){
scanf("%d%d",&c,&d);
for(int i=c;i<=d;i++)
a[i]=1;
}
for(int i=0;i<=l;i++){
if(a[i]==0)sum++;
}
printf("%d",sum);
return 0;
}