"""依图笔试第三套第一题,数组交换""" import sys n = int(input()) nums = list(map(int,input().split())) dicts = {} sort_nums = sorted(nums) for i in range(len(sort_nums)):     dicts[sort_nums[i]] = i cnt = 0 flag = [False]*len(nums) for i in range(len(nums)):     if not flag[i]:         j = i         while not flag[j]:             flag[j] = True             j = dicts[nums[j]]         cnt += 1 print(len(nums) - cnt)
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务