Sirius_H2SO4 @ 2023-07-11 11:06:01
#include<iostream>
using namespace std;
int tree[11451],l,m,u[11451],v[11451],remain=0;
int main()
{
cin >> l >> m;
l++;
for(int i=1;i<=m;i++){
cin >> u[i] >> v[i];
}
for(int i=1;i<=l;i++){
tree[i]=1;
}
for(int i=1;i<=m;i++){
for(int s=u[i];s<=v[i];s++){
if(tree[s])tree[s]=0;
}
}
for(int i=1;i<=l;i++){
if(tree[i])remain++;
}
cout << remain;
}
感谢各位大佬qwq
by xuzihao123 @ 2023-07-11 11:07:39
@ThisIsSirius_859
从0开始
by Sirius_H2SO4 @ 2023-07-11 11:17:24
@xuzihao123
#include<iostream>
using namespace std;
int tree[11451],l,m,u[11451],v[11451],remain=0;
int main()
{
cin >> l >> m;
l++;
for(int i=0;i<m;i++){
cin >> u[i] >> v[i];
}
for(int i=0;i<=l;i++){
tree[i]=1;
}
for(int i=0;i<=m;i++){
for(int s=u[i];s<=v[i];s++){
if(tree[s])tree[s]=0;
}
}
for(int i=0;i<=l;i++){
if(tree[i])remain++;
}
cout << remain;
}
跪谢大佬!!!但交完还是WA#1...
by xuzihao123 @ 2023-07-11 11:20:25
@ThisIsSirius_859
这种思路我不太会,我私信给你将一下我的思路吧