yuxiaoyu20090104 @ 2022-08-16 19:17:03
#include<iostream>
using namespace std;
int a[1005];
int m, l;
int main()
{
cin >> l >> m;
for (int i = 1; i <= m; i++)
{
int x, y;
cin >> x >> y;
for (int j = x; j <= y; j++)a[j] = 1;
}
int cnt = 0;
for (int i = 1; i <= l; i++)
if (a[i] == 0)
cnt++;
cout << cnt << endl;
return 0;
}
by _i_i_ @ 2022-08-16 19:21:38
@xiaoxiao090104 数组大小
by JustinXiaoJunyang @ 2022-08-16 19:21:45
@xiaoxiao090104 求关注~
#include <iostream>
using namespace std;
int main()
{
int l, m;
cin >> l >> m;
int start, stop;
int left = 0;
bool a[l];
for (int i = 0; i <= l; i++)
{
a[i] = true;
}
for (int i = 1; i <= m; i++)
{
cin >> start >> stop;
for (int j = start; j <= stop; j++)
{
a[j] = false;
}
}
for (int i = 0; i <= l; i++)
{
if (a[i] == true)
{
left++;
}
}
cout << left << endl;
return 0;
}
by seanlsy @ 2022-08-16 19:23:36
额下面那个循环应当从 1 开始
by yuxiaoyu20090104 @ 2022-08-16 19:30:20
@seanlsy 不是吧,马路的开端是0诶
by yuxiaoyu20090104 @ 2022-08-16 19:30:51
@__uint32_t 好的谢谢,已经AC了
by seanlsy @ 2022-08-16 19:36:20
@xiaoxiao090104 抱歉打错了
by gongziwen @ 2022-08-16 20:00:33
@JustinXiaoJunyang
bool a[l];