Xiao_Fun @ 2023-11-16 22:52:56
a = input().split()
l = int(a[0]) + 1
m = int(a[1])
contain = []
for i in range(m):
b = input().split()
contain.append(int(b[0]))
contain.append(int(b[1]))
l = l - contain[1] + contain[0] -1
for i in range(m-1):
if contain[i+3] < contain[i+1] and contain[i] < contain[i+3] and contain[i] > contain[i+2]:
l = l - contain[i] + contain[i+2]
elif contain[i+1] > contain[i+2] and contain[i+1] < contain[i+3] and contain[i] < contain[i+2]:
l = l - contain[i+3] + contain[i+1]
elif contain[i+3] < contain[i+1] and contain[i] < contain[i+2]:
continue
else:
l = l - contain[i+4] + contain[i+3] -1
print(l)
by nibuxvyaozhidao @ 2023-11-17 20:04:26
a = input().split()
l = int(a[0]) + 1
m = int(a[1])
contain = []
for i in range(m):
b = input().split()
contain.append(int(b[0]))
contain.append(int(b[1]))
print('debug',l)
l = l - contain[1] + contain[0] -1
for i in range(m-1):
print('debug',l)
if contain[i+3] < contain[i+1] and contain[i] < contain[i+3] and contain[i] > contain[i+2]:
l = l - contain[i] + contain[i+2]
elif contain[i+1] > contain[i+2] and contain[i+1] < contain[i+3] and contain[i] < contain[i+2]:
l = l - contain[i+3] + contain[i+1]
elif contain[i+3] < contain[i+1] and contain[i] < contain[i+2]:
continue
else:
l = l - contain[i+4] + contain[i+3] -1
print(l)
input:
100 3
1 100
2 30
40 60
output:
debug 101
debug 1
debug 1
-20
感觉是你的代码只考虑两个邻近的区间,导致的。