xingjielong @ 2023-10-16 20:49:42
include<bits/stdc++.h>
using namespace std;
int main(){ int l,m,c,b;
scanf("%i%i",l,m);
int a[l];
for(int i = 1;i <= m;i++){
scanf("%i%i",b,c);
for(int j = b - 1;j < c; j++){
a[j1] = 1;
}
}
int num = 0;
for(int i = 0;i < l;i++){
if(a[i] != 1) num++;
}
printf("%i",num);
return 0;
}
by Nekopedia @ 2023-10-16 20:52:19
@xingjielong 你输入时去掉区间里面的树应该是a[j] = 1
by MsgNotFound @ 2023-10-16 20:52:38
输入的时候,%i
是什么?还有,第一个双重循环里面,a[j1]=1;
这一句也有错误,没有j1这个变量.
@xingjielong
by MsgNotFound @ 2023-10-16 20:59:35
只能给你改到wa了,不知道为什么一用scanf和printf就会RE。
code:
#include<bits/stdc++.h>
using namespace std;
int main(){
int l,m,c,b;
cin>>l>>m;
const int L=l;
int a[L];
for(int i = 1;i <= m;i++){
cin>>b>>c;
for(int j = b - 1;j <= c; j++){
a[j] = 1;
}
}
int num = 0;
for(int i = 1;i <= L;i++){
if(a[i] != 1) num++;
}
cout<<num;
return 0;
}
by lovely_Rex @ 2023-10-16 21:01:17
你的输入不对,l和m前面要加&,不加就RE
by lovely_Rex @ 2023-10-16 21:02:09
或者说你用cin
by lovely_Rex @ 2023-10-16 21:06:38
还有,
int a[l]改成a[10005]
by xingjielong @ 2023-10-19 21:05:33
谢谢!