123456rita @ 2022-10-15 13:14:40
#include<stdio.h>
int main()
{
int i=0;
int L,m;
int initial,end;
int a[L+1];
int cnt=0;
scanf("%d %d",&L,&m);
for(i=0;i<L+1;i++){
a[i]=0;
}
for(i=0;i<m;i++){
scanf("%d %d",&initial,&end);
if(i>=initial&&i<=end,i++){
a[i]=1;
}
}
for(i=0;i<L+1;i++){
if(a[i]==0){
cnt++;
}
}
printf("%d",cnt);
return 0;
}
by _ZXWDS @ 2022-10-15 13:17:54
建议说一下各部分是干嘛的
by X_ray_Of_the_way @ 2022-10-15 13:49:48
if(i>=initial&&i<=end,i++){ a[i]=1; } if 改为for 试试
by X_ray_Of_the_way @ 2022-10-15 13:50:25
for(int i=initial;i<=end;i++)
by X_ray_Of_the_way @ 2022-10-15 13:53:37
@123456rita 在吗?
by X_ray_Of_the_way @ 2022-10-15 13:57:40
我先参加月赛了,待会再看看
by 123456rita @ 2022-10-15 19:38:21
@X_ray_Of_the_way 好的,谢谢
by X_ray_Of_the_way @ 2022-10-16 07:20:48
你看看我的代码:
#include<iostream>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<map>
#include<set>
using namespace std;
const int N=1e5+10;
bool tree[10001];
int n,l;
int main(){
cin>>l>>n;
for(int i=1;i<=n;i++){
int x,y;
cin>>x>>y;
for(int i=x;i<=y;i++){
tree[i]=1;
}
}
int sum=0;
for(int i=0;i<=l;i++){
if(!tree[i])
sum++;
}
cout<<sum<<endl;
return 0;
}
by X_ray_Of_the_way @ 2022-10-16 07:21:57
应该是你用了一个变量来定义数组的问题