licy3102 @ 2024-11-02 21:48:20
#include<bits/stdc++.h>
int main(){
int a,b,x,c;
scanf("%d %d",a,b);
int y,z,d[a]={0};
for(x=0;x<=b;x++){
scanf("%d %d",y,z);
for(c=y;c<=z;c++){
d[c]=1;
}
}
y=0;
for(x=0;x<=a;x++){
if(d[x]==0){
y++;
}
}
printf("%d",y);
return 0;
}
by licy3102 @ 2024-11-02 21:54:04
全RE
by yuechenxi130407 @ 2024-11-02 22:16:09
@licy3102
1.没加
using namespace std;
2.在
scanf的数据前面要加&
3.数组好像不能用变量做长度吧
by BobBoh @ 2024-11-03 16:26:32
for循环如果要从0开始,就不能用<=;要用<=,就要从1开始
by licy3102 @ 2024-11-03 18:09:20
@yuechenxi130407 不用加吧,没用cin >>,cout <<
by licy3102 @ 2024-11-03 18:09:51
@BobBoh 谢谢!
by licy3102 @ 2024-11-03 21:19:34
@BobBoh ```cpp
int main(){ int a,b,x,c; scanf("%d %d",&a,&b); int y,z,d[a]={0}; for(x=0;x<=b;x++){ scanf("%d %d",&y,&z); for(c=y;c<=z;c++){ d[c]=1; } } y=0; for(x=1;x<=a;x++){ if(d[x]==0){ y++; } } printf("%d",y); return 0; }
by licy3102 @ 2024-11-03 21:20:13
@yuechenxi130407 确实!&
by licy3102 @ 2024-11-03 21:59:43
@BobBoh ```cpp
10分..
by xqx2152 @ 2024-11-04 21:14:28
#include<iostream>
using namespace std;
int main(){
int n,q,l,r,a[10005],ans;
cin >> n >> q;
ans = n + 1;
for (int i = 0;i <= n;i++){
a[i] = 1;
}
for (int i = 1;i <= q;i++){
cin >> l >> r;
for (int j = l;j <= r;j++){
if (a[j] != 0){
a[j] = 0;
ans -= 1;
}
}
}
cout << ans;
return 0;
}
by BobBoh @ 2024-11-09 14:53:27
@licy3102 计算部分要从0开始,要代码的时候@BobBoh,我再发