Liyuhui222 @ 2025-01-08 10:37:05
#include<bits/stdc++.h>
using namespace std;
bool f[10005];
int main()
{
int n,q;
cin >> n >> q;
for(int i = 1;i <= q;i++)
{
int l,r;
cin >> l >> r;
for(int j = l;j <= r;j++)
{
f[j] = 1;
}
}
int cnt = 0;
for(int i = 1;i <= n;i++)
{
if(f[i] == 0)
{
cnt++;
}
}
cout << cnt;
}
by liuzhuoran141516 @ 2025-01-08 10:42:45
没读题吗
#include<bits/stdc++.h>
using namespace std;
bool f[10005];
int main()
{
int n,q;
cin >> n >> q;
for(int i = 1;i <= q;i++)
{
int l,r;
cin >> l >> r;
for(int j = l;j <= r;j++)
{
f[j] = 1;
}
}
int cnt = 0;
for(int i = 0;i <= n;i++)
{
if(f[i] == 0)
{
cnt++;
}
}
cout << cnt;
}
by liuzhuoran141516 @ 2025-01-08 10:42:54
@Liyuhui222
by 4041nofoundGeoge @ 2025-01-08 10:43:18
@Liyuhui222最后一个循环下标从 0 开始。
by Liyuhui222 @ 2025-01-08 10:59:57
...谢了
by Liyuhui222 @ 2025-01-09 09:11:11
@4041nofoundGeoge\
@liuzhuoran141516\
(感觉没脸见人了) 谢了......