goto_FLY @ 2024-10-14 16:50:11
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int l, m,n=0;
cin >> l >> m;
int u, v;
bool a[10001];
memset(a, 0, sizeof(a));
for (int i = 0; i < m; i++)
{
cin >> u >> v;
for (int i = u; i <= v; i++)
a[i] = 1;
}
for (int i = 0; i < l; i++)
{
if (a[i] == 1) n++;
}
cout << l+1-n << endl;
return 0;
}
by w135 @ 2024-10-14 16:51:39
for (int i = u-1; i <= v-1; i++) a[i] = 1;
by doooge @ 2024-10-14 16:53:37
for(int i=u-1;i<v;i++)
by w135 @ 2024-10-14 16:58:00
对了那一行是j
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int l, m,n=0;
cin >> l >> m;
int u, v;
bool a[10001];
memset(a, 0, sizeof(a));
for (int i = 0; i < m; i++)
{
cin >> u >> v;
for (int j = u-1; j <= v-1; j++)
a[j] = 1;
}
for (int i = 0; i < l; i++)
{
if (a[i] == 1) n++;
}
cout << l+1-n << endl;
return 0;
}
剩下一个点就是你思路问题了
by goto_FLY @ 2024-10-16 10:45:54
@w135 谢谢佬
by goto_FLY @ 2024-10-16 10:46:16
@doooge Thanks♪(・ω・)ノ