kikyo464 @ 2022-04-24 11:15:35
#include<stdio.h>
int main()
{
int l, m, u[100] = { 0 }, v[100] = { 0 }, i, j, k, n;
scanf("%d%d",&l,&m);
for (i = 0; i < m; i++)
scanf("%d%d",&u[i],&v[i]);
for (i = 0; i < m; i++)
{
for (j = 0; j < m; j++)
{
if (v[i] >= u[j] && v[i] <= v[j]&&u[i]<=u[j]&&i!=j)
v[i] = v[j], u[j] = 0, v[j] = -1;
else if (v[i] >= v[j]&&u[i]<=u[j]&&u[i]<=v[j]&&i!=j)
u[j] = 0, v[j] = -1;
}
}
for (i = 0, k = 0; i < m; i++)
k += v[i] - u[i] + 1;
n = l + 1 - k;
printf("%d", n);
return 0;
}
by _Harry_Potter_ @ 2022-04-24 11:18:25
#include<iostream>
using namespace std;
int l,m,u,v,cnt;
bool a[10005];
int main(){
cin >> l >> m;
for(int i = 0;i <= l;i++) a[i] = 1;
for(int i = 1;i <= m;i++){
cin >> u >> v;
for(int j = u;j <= v;j++) a[j] = 0;
}
for(int i = 0;i <= l;i++)
if(a[i]) cnt++;
cout << cnt << endl;
return 0;
}
自己看一下有什么错,有事在这个帖子里跟我说
by _Harry_Potter_ @ 2022-04-24 11:19:00
我的是C++
by kikyo464 @ 2022-04-24 12:13:03
@_HarryPotter 看了一下你的思路,重新写了一个,通过了,谢谢