Piling Up!
问题描述
样例演示
STDIN Function
----- --------
2 T = 2
6 blocks[] size n = 6
4 3 2 1 3 4 blocks = [4, 3, 2, 1, 3, 4]
3 blocks[] size n = 3
1 3 2 blocks = [1, 3, 2]
Yes
No
参考代码
from collections import deque
N = int(input())
for _ in range(N):
flag = True
input()
d = deque(map(int, input().strip().split()))
if(d[0] >= d[-1]):
max = d.popleft()
else:
max = d.pop()
while d:
if(len(d)==1):
if(d[0] <= max):
break
else:
flag = False
break
else:
if(d[0]<=max and d[-1]<=max):
if(d[0]>=d[-1]):
max = d.popleft()
else:
max = d.pop()
elif(d[0]<=max):
max = d.popleft()
elif(d[-1]<=max):
max = d.pop()
else:
flag = False
break
if flag:
print("Yes")
else:
print("No")
- 代码转载https://blog.csdn.net/huatian5/article/details/78503761
from collections import deque
T = int(input())
for case in range(T):
n = int(input())
ls = list(map(int,input().split()))
pos = ls.index(min(ls))
left = ls[:pos]
right = ls[pos:]
if left == sorted(left,reverse=True) and right == sorted(right):
print("Yes")
else:
print("No")
总结
- from collections import deque代表从collections模块中导入双向队列