每个案例第一行为此数组元素个数k(4<k<80),第二行是k个整数,每两个整数之间用空格分隔
每个案例输出为n个数字(其中n为该案例中极值点的个数):每个数字对应相应数组的相应极值点下标值,下标值之间用空格分隔。
10 10 12 12 11 11 12 23 24 12 12 15 12 12 122 112 222 211 222 221 76 36 31 234 256 76 76 15 12 14 122 112 222 222 222 221 76 36 31 234 256 76 73
0 7 2 3 4 5 6 10 12 0 2 3 10 12 14
while True: try: n=int(input().strip()) inp=list(map(int,input().strip().split(' '))) list1=[] for i in range(n): if i==0: if inp[i]<inp[i+1] or inp[i]>inp[i+1]: list1.append(str(i)) elif i==n-1: if inp[i]<inp[i-1] or inp[i]>inp[i-1]: list1.append(str(i)) else: if inp[i]<inp[i-1] and inp[i]<inp[i+1]: list1.append(str(i)) elif inp[i]>inp[i-1] and inp[i]>inp[i+1]: list1.append(str(i)) print(' '.join(list1)) except: break
try: while True: num,digitNum,result = int(input()),list(map(int,input().split())),[] if digitNum[0] != digitNum[1]: result.append(0) for i in range(1,num-1): if digitNum[i-1] < digitNum[i] > digitNum[i+1] or digitNum[i-1] > digitNum[i] < digitNum[i+1]: result.append(i) if digitNum[-1] != digitNum[-2]: result.append(num-1) print(" ".join(map(str,result))) except Exception: pass
def filterPeak(arr):
a = list(
filter(lambda i: (arr[i] < arr[i - 1] and arr[i] < arr[i + 1]) or (arr[i] > arr[i - 1] and arr[i] > arr[i + 1]),
range(1, len(arr) - 1)))
b = [0] if arr[0] != arr[1] else []
c = [len(arr) - 1] if arr[-2] != arr[-1] else []
return b + a + c
a, b = input(), list(map(int, input().split()))
print(" ".join(map(str, filterPeak(b))))
#求大神指教,哪个地方编错了??一直调试不出来 def f(x): a=[] for i in range(len(x)): if i==0: if x[i] != x[1]: a.append(str(i)) if i==len(x)-1: if x[i] != x[1]: a.append(str(i)) if 1<=i<=len(x)-2: if x[i-1]<x[i]>x[i+1] or x[i-1]>x[i]<x[i+1]: a.append(str(i)) return ' '.join(a) while 1: try: for i in range(int(input())): num=int(input()) s=list(map(int,input().split())) print(f(s)) except: break
def ExtremePoint(L, n): result = [] if L[0] != L[1]: result.append(0) for i in xrange(1, n - 1): if (L[i] < L[i - 1] and L[i] < L[i + 1]) or (L[i] > L[i - 1] and L[i] > L[i + 1]): result.append(i) if L[-1] != L[-2]: result.append(n - 1) return ' '.join(map(str, result)) try: while 1: for case in xrange(input()): n = input() Arr = map(int, raw_input().split()) print ExtremePoint(Arr, n) except: pass