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:47:51
搞个数组吧@zhouyf828
by zhouyf828 @ 2023-08-29 20:49:16
@liulechen 怀疑我的方法漏考虑包含了,我改下试试
by ybchenyuyang @ 2023-08-29 20:49:23
@liulechen az,有没有种可能,python里的叫列表
by liu_le_chen @ 2023-08-29 20:49:26
赞同(@cyyyyds857 )
by zhouyf828 @ 2023-08-29 20:49:43
@liulechen 我就是用2维数组的
by liu_le_chen @ 2023-08-29 20:50:03
我不懂呀我是python外行@cyyyyds857
by ybchenyuyang @ 2023-08-29 20:50:39
@liulechen 我也没学过
by liu_le_chen @ 2023-08-29 20:50:42
一维不就行了吗@zhouyf828
by liu_le_chen @ 2023-08-29 20:51:52
你们有老师吗?@zhouyf828
by zhouyf828 @ 2023-08-29 20:53:00
@cyyyyds857 用列表表示数组,如果要严谨一点就要加numpy库