求助,Python前三个点RE(自学的Python刚开始不喜勿喷)

P1047 [NOIP2005 普及组] 校门外的树

071228xx @ 2023-04-05 16:52:14

lis = list(input().split())
len = int(lis[0])
a = int(lis[1])
i = 0
l = [0] * len
u = v = 0
count = len + 1
import sys
while(i < a):
    u , v = map(int , input().split())
    if(u > v):
        sys.exit()
    while(u <= v):
        if(l[u] == 0):
            l[u] = 1
            count -= 1
        u += 1
    i += 1
print(count)

by wanglexi @ 2023-10-31 19:32:17

你怎么能l = [0] * len呢?

因为树种在0\sim l处,总共有l+1项,所以l = [0] * len应该为l = [0] * (len+1)

```python lis = list(input().split()) len = int(lis[0]) a = int(lis[1]) i = 0 l = [0] * (len+1) u = v = 0 count = len + 1 import sys while(i < a): u , v = map(int , input().split()) if(u > v): sys.exit() while(u <= v): if(l[u] == 0): l[u] = 1 count -= 1 u += 1 i += 1 print(count) ```

by wanglexi @ 2023-10-31 19:32:38

@071228xx


|