jh2023 @ 2023-08-07 17:29:14
大佬求助啊,第一个WA。。。
#include <bits/stdc++.h>
using namespace std;
int f[100000];
int main() {
int l, m;
int a, b;
cin >> l >> m;
for (int i = 1; i <= l; i++) {
f[i] = 1;
}
for (int i = 1; i <= m; i++) {
cin >> a >> b;
for (int j = a; j <= b; j++) {
f[j] = 0;
}
}
int total = 0;
for (int i = 1; i <= l; i++) {
total += f[i];
}
cout << total + 1;
return 0;
}
by liu_le_chen @ 2023-08-07 17:47:48
#include <bits/stdc++.h>
using namespace std;
int f[100000];
int main() {
int l, m;
int a, b;
cin >> l >> m;
for (int i = 0; i <= l; i++) {
f[i] = 1;
}
for (int i = 1; i <= m; i++) {
cin >> a >> b;
for (int j = a; j <= b; j++) {
f[j] = 0;
}
}
int total = 0;
for (int i = 0; i <= l; i++) {
total+=f[i];
}
cout << total;
return 0;
}
by liu_le_chen @ 2023-08-07 17:49:10
注意审题,马路的开头是0,结尾时l