Eagle233 @ 2024-10-19 22:07:30
#include <stdio.h>
#include <stdbool.h>
int main(void)
{
int l, m;
scanf("%d %d", &l, &m);
bool trees[l + 1];
for (int i = 0; i < l + 1; i++)
{
trees[i] = true;
}
int range_1[m], range_2[m];
for (int i = 0; i < m; i++)
{
scanf("%d %d", &range_1[i], &range_2[i]);
}
for (int i = 0; i < m; i++)
{
for (int j = range_1[i] - 1; j < range_2[i]; j++)
{
if (trees[j])
{
trees[j] = false;
}
}
}
int tree = 0;
for (int i = 0; i < l + 1; i++)
{
if (trees[i])
{
tree++;
}
}
printf("%d\n", tree);
}
by LIUHAOYU2013 @ 2024-10-20 22:13:45
@Eagle233
#include <bits/stdc++.h>
using namespace std;
int l,m;
int vis[100005];
int x,y;
int ans;
int main()
{
cin>>l>>m;
for(int i=0;i<=l;i++)
{
vis[i]=1;
}
for(int i=1;i<=m;i++)
{
cin>>x>>y;
for(int j=x;j<=y;j++)
{
vis[j]=0;
}
}
for(int i=0;i<=l;i++)
{
if(vis[i]==1) ans++;
}
cout<<ans;
return 0;
}