zhouyf828 @ 2023-08-29 20:30:26
a=input()+' '
for i in range(len(a)):
if a[i]==" ":
cd=int(a[0:i]) #cd马路长度
qy=int(a[i+1:-1]) #区域数目
break
q2=[[0 for i in range(2)] for j in range(qy)] #q2储存起始点终止点
for j in range(qy):
b=input()+' '
for k in range(len(b)):
if b[k]==" ":
qd=int(b[0:k])
zd=int(b[k+1:-1])
q2[j][0]=qd
q2[j][1]=zd
break
for i in range(1,len(q2)): #感觉是这后面出了问题
for j in range(i,len(q2)):
if q2[j][1]>=q2[i-1][0] and q2[j][0]<q2[i-1][0]:
q2[i-1][0]=q2[j][0]
q2[j][1],q2[j][0]=-1,-1
elif q2[j][0]<=q2[i-1][1] and q2[j][1]>q2[i-1][1]:
q2[i-1][1]=q2[j][1]
q2[j][1],q2[j][0]=-1,-1
for i in range(len(q2)):
if q2[i][0]!=-1:
cd-=q2[i][1]-q2[i][0]+1
cd+=1
print(cd)
希望有大佬帮忙看看
by liu_le_chen @ 2023-08-29 20:35:21
碰到在要建地铁区域里面的树那么就打上标记,然后最后统计没有打标记的位置然后输出就行了。
by kkksbsbsbssb @ 2023-08-29 20:35:49
@zhouyf828
#include <bits/stdc++.h>
using namespace std;
main() {
bool a[100010];
int l,m,u,v,num = 0;
cin >> l >> m;
for(int i = 0; i <= l;i++) {
a[i] = 1;
}
for(int i =0 ;i < m;i++) {
cin >> u >> v;
for(int j =u;j<=v;j++)
{
a[j] = 0;
}
}
for(int i =0; i<=l;i++) {
if(a[i]) num++;
}
cout << num ;
}
by liu_le_chen @ 2023-08-29 20:36:07
你这是c++吗?
by liu_le_chen @ 2023-08-29 20:36:46
别直接发代码呀
by liu_le_chen @ 2023-08-29 20:37:06
@kkksbsbsbssb
by liu_le_chen @ 2023-08-29 20:37:20
@zhouyf828
by zhouyf828 @ 2023-08-29 20:37:52
@liulechen 这是python
by liu_le_chen @ 2023-08-29 20:38:39
那我就只提思路了
by zhouyf828 @ 2023-08-29 20:38:46
@kkksbsbsbssb 还没学过C++看不懂抱歉
by zhouyf828 @ 2023-08-29 20:39:31
@liulechen 我想知道我后面那段代码哪里错了,我暴力枚举做出来了