Zzy20060323 @ 2024-09-06 16:38:25
#include<stdio.h>
int a[1000][2];
int b[1000];
int main()
{
int l, m,num;
scanf("%d%d", &l, &m);
for (int i = 0; i < m; i++)
{
scanf("%d%d", &a[i][0], &a[i][1]);
}
num = l + 1;
for (int i = 0; i < m; i++)
{
for (int j = a[i][0]; j <= a[i][1]; j++)
{
b[j] = 1;
}
}
for (int k = 0; k < l + 1; k++)
{
if (b[k] == 1)
{
num--;
}
}
printf("%d", num);
return 0;
}
by Yxy7952 @ 2024-09-06 16:42:42
@Zzy20060323
数组开大点
#include<stdio.h>
int a[10005][2];
int b[10005];
int main()
{
int l, m,num;
scanf("%d%d", &l, &m);
for (int i = 0; i < m; i++)
{
scanf("%d%d", &a[i][0], &a[i][1]);
}
num = l + 1;
for (int i = 0; i < m; i++)
{
for (int j = a[i][0]; j <= a[i][1]; j++)
{
b[j] = 1;
}
}
for (int k = 0; k < l + 1; k++)
{
if (b[k] == 1)
{
num--;
}
}
printf("%d", num);
return 0;
}
by hanxiaofensheng @ 2024-09-06 17:01:08
#include <bits/stdc++.h>
using namespace std;
int l, m, a, b, c[10001]={0}, ans;
int main(){
cin>> l>> m;
for(int i=1;i<=m;i++){
cin>> a>> b;
for(int j=a;j<=b;j++) c[j]=1;
}
for(int i=0;i<=l;i++) if(c[i]==0) ans++;
cout<<ans;
return 0;
}
求关注
by White___Fox @ 2024-09-26 08:37:10
我是大佬,但我不想告诉你