louzhu @ 2023-04-22 12:43:06
这题我是这么做的:
#include <bits/stdc++.h>
using namespace std;
bool a[10004];
int main()
{
int l;
int m;
cin >> l >> m;
for(int i = 1; i <= l; i++)
{
a[i] = 1;
}
for(int i = 1; i <= m; i++)
{
int u , v;
cin >> u >> v;
for(int i = u; i <= v; i++)
{
a[i] = 0;
}
}
int cnt = 0;
for(int i = 1; i <= l; i++)
{
if(a[i] == 1)
{
cnt++;
}
}
cout << cnt << endl;
}
by Katz @ 2023-04-22 12:44:05
让我猜猜,你的循环都是从1开始的,但是题目里面是从0开始的
by bjpenguin @ 2023-12-06 19:29:08
@Katz 同意
by louzhu @ 2024-01-18 13:17:02
@Katz 哇谢谢~