invild @ 2024-09-03 10:05:13
#include <stdio.h>
int main(){
int l, m;
int area[100][2];
scanf("%d %d", &l, &m);
int num = 0;
for (int i = 0; i < m; i++)
{
scanf(" %d %d", &area[i][0], &area[i][1]);
}
for (int j = 0; j < l; j++)
{
int flag = 0;
for (int k = 0; k < m; k++)
{
if ((j>=area[k][0])&&(j<=area[k][1]))
{
flag = 1;
}
}
if (flag==1)
{
num = num + 1;
}
}
printf("%d", l + 1 - num);
return 0;
}
by StarRoam @ 2024-09-03 10:17:00
#include <bits/stdc++.h>
using namespace std;
int main(){
int l, m;
int area[100][2];
scanf("%d %d", &l, &m);
int num = 0;
for (int i = 0; i < m; i++)
{
scanf(" %d %d", &area[i][0], &area[i][1]);
}
for (int j = 0; j <= l; j++)
{
int flag = 0;
for (int k = 0; k < m; k++)
{
if ((j>=area[k][0])&&(j<=area[k][1]))
{
flag = 1;
}
}
if (flag==1)
{
num = num + 1;
}
}
printf("%d", l + 1 - num);
return 0;
}
@invild
by StarRoam @ 2024-09-03 10:18:18
j的范围是: 0<=j<=l