标签:
Nothing special, just some corner cases
n = int(input()) arr = [int(i) for i in input().strip().split()] # Collect rec = [] i = 0 while i < n - 1: if arr[i] > arr[i + 1]: inx = i cnt = 1 while i < n - 1 and arr[i] > arr[i + 1]: cnt += 1 i += 1 rec.append((inx, cnt)) else: i += 1 # Check if len(rec) == 1: if rec[0][1] == 2: if rec[0][0] + 1 < n - 1 and arr[rec[0][0]] > arr[rec[0][0] + 2]: print ("no") else: print ("yes") print ("swap %d %d" % (rec[0][0] + 1, rec[0][0] + 2)) elif rec[0][1] > 2: if rec[0][0] + rec[0][1] - 1 < n - 1 and arr[rec[0][0]] > arr[rec[0][0] + rec[0][1]]: print ("no") else: print ("yes") print ("reverse %d %d" % (rec[0][0] + 1, rec[0][0] + rec[0][1])) elif len(rec) == 2 and rec[0][1] == 2 and rec[1][1] == 2: print ("yes") print ("swap %d %d" % (rec[0][0] + 1, rec[1][0] + 2)) else: print ("no")
标签:
原文地址:http://www.cnblogs.com/tonix/p/4346126.html