GSNB123 @ 2022-10-22 17:37:48
#include<stdio.h>
int main()
{
int l,m,u,v,i,j,a,sum;
int t[10001]={0};
scanf("%d %d\n",&l,&m);
for(i=0;i<=l;i++){
t[i]=1;
}
for(j=0;j<m;j++){
scanf("%d %d\n",&u,&v);
t[i]=0;
}
for(a=0;a<=l;a++)
if(t[i]==1)
sum++;
printf("%d",&sum);
return 0;
}
by pengzihao @ 2022-10-22 17:45:52
m是区域的数目,u和v才是区域的范围
by GSNB123 @ 2022-10-23 18:15:46
@pengzihao 大佬帮我改一下
by pengzihao @ 2022-10-24 19:38:17
@GSNB123 不过你可以先借鉴一下我店AC代码
#include <iostream>
using namespace std;
int L,m,x,y,ans;
bool su[10001];
int main()
{
cin>>L>>m;
for(int i=0;i<=L;i++){
su[i]=true;
}
for(int i=1;i<=m;i++){
cin>>x>>y;
for(int j=x;j<=y;j++){
su[j]=false;
}
}
for(int i=0;i<=L;i++){
if(su[i]){
ans++;
}
}
cout<<ans;
return 0;
}