LorryWayn @ 2023-03-26 16:25:10
int tree[1001]={0};
scanf("%d %d",&l,&m);
for(i=0;i<=l;i++){
tree[i]=i;
}
for(i=0;i<m;i++){
scanf("%d %d",&u,&v);
for(j=u;j<=v;j++){
tree[j]=-1;
}
}
for(i=0;i<=l;i++){
if(tree[i]!=-1){
sum++;
}
}
printf("%d\n",sum);
return 0;
}
by LinGxIao_0230 @ 2023-03-26 16:28:52
您用的是 goc 编译器吧怎么没有头文件
by codejiahui @ 2023-03-26 16:59:16
@LorryWayn 就问头文件和int main
是被您吃了吗
by LorryWayn @ 2023-03-26 17:28:19
没有,头文件啥的我只是没粘上去
by LorryWayn @ 2023-03-26 17:28:46
@codejiahui 没有,头文件啥的我只是没粘上去
by codejiahui @ 2023-03-26 18:34:42
@LorryWayn
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a[10010];
int main()
{
int l,m,ans = 0;
scanf("%d%d",&l,&m);
for (int i = 1;i <= m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
for (int j = x;j <= y;j++)
a[j] = 1;
}
for (int i = 0;i <= l;i++)
if (a[i] == 0)
ans++;
printf("%d\n",ans);
return 0;
}
by codejiahui @ 2023-03-26 18:35:50
@LorryWayn 还有,
for(i=0;i<=l;i++){
tree[i]=i;
}
根本不需要
by LorryWayn @ 2023-03-26 22:27:03
@codejiahui 10的四次方是啥,我没用这个啊
by codejiahui @ 2023-03-27 18:11:02
@LorryWayn int tree[1001]={0};
by LorryWayn @ 2023-03-27 18:23:12
@codejiahui 明白了谢谢!