Not_lazy_II @ 2022-12-10 14:32:34
#include<bits/stdc++.h>
int a[10001];
int main(){
int l,m,u,v;
scanf("%d %d",&l,&m);
for(int j=u;j<=v;j++){
scanf("%d %d",&u,&v);
a[j]=1;
}
int sum=1;
for(int i;i<=l;i++){
if(a[i]==0) sum++;
printf("%d",sum);
}
return 0;
}
by juruo_zxt @ 2022-12-10 14:44:16
第一个for循环咋回事
by mibamiba @ 2022-12-10 14:45:31
第八行什么鬼,uv不是还没输入吗
by juruo_zxt @ 2022-12-10 14:47:54
为啥是
for(int j=u;j<=v;j++){
scanf("%d %d",&u,&v);
a[j]=1;
}
,不是应该m次输入u、v在算a值吗
by xhz0311 @ 2022-12-10 14:56:21
拿我的满分代码给你看看
#include <cstdio>
using namespace std;
int main()
{
int l,n,count=0;
scanf("%d %d",&l,&n);
int a[l+1],b[n][2];
for (int i=0; i<=l; i++)
{
a[i]=1;
}
for (int i=0; i<n; i++)
{
scanf("%d %d",&b[i][0],&b[i][1]);
}
for (int i=0; i<n; i++)
{
for (int j=b[i][0]; j<=b[i][1]; j++)
{
a[j]=0;
}
}
for (int i=0; i<=l; i++)
{
if (a[i]==1)
{
count++;
}
}
printf("%d",count);
return 0;
}
全AC
by Alone_Moonking @ 2022-12-10 16:09:55
#include<iostream>
using namespace std;
int main()
{
int L,M,i,j;
int section[10001]= {0};
int a,b,tree_sum=0,tree_ex,tree_new;
cin>>L>>M;
for (i=0; i<M; i++)
{
cin>>a>>b;
for(j=a; j<=b; j++)
section[j]=1;
}
for(i=0; i<=L; i++)
if(section[i]==1)
tree_sum++;
tree_ex=L+1;
tree_new=tree_ex-tree_sum;
cout<<tree_new<<endl;
return 0;
}
不知道有没有参考价值