解题思路:
注意事项:
参考代码:
def trainSchedule(n, order):
stack = []
next_car = 1
for car in order:
while (len(stack) == 0 or stack[-1] != car) and next_car <= n:
stack.append(next_car)
next_car += 1
if stack[-1] == car:
stack.pop()
else:
return "NO"
return "YES"
# 读取输入
n = int(input())
order = list(map(int, input().split()))
# 调度车厢并判断能否得到指定的顺序
result = trainSchedule(n, order)
# 输出结果
print(result)
0.0分
2 人评分
格式错误一万年,,有没有过了的来看看(终于过了)浏览:919 |
点我有惊喜!你懂得!浏览:1515 |
简单的a+b (C语言代码)浏览:717 |
C语言训练-素数问题 (C语言代码)浏览:998 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:596 |
WU-蓝桥杯算法提高VIP-企业奖金发放 (C++代码)浏览:1175 |
文科生的悲哀 (C语言代码)浏览:1401 |
打印十字图 (C语言代码)浏览:2710 |
母牛的故事 (C语言代码)浏览:944 |
1051(奇了怪了)浏览:649 |