```python import math def min_operations(n, a): # 存储数字及其出现次数 num_count = {} for num in a: if num in num_count: num_count[num] += 1 else: num_count[num] = 1 operation_count = 0 # 处理可直接删除的相同数字段 for num, count in num_count.items(): if count > 1: start = -1 for i in range(n): if a[i] == num and start == -1: start = i elif a[i]!= num and start!= -1: if i - start >= 2: operation_count += 1 start = -1 # 对剩余数字进行交换操作 sorted_a = sorted(a) for i in range(n): if a[i]!= sorted_a[i]: for j in range(i + 1, n): if a[j] == sorted_a[i]: a[i], a[j] = a[j], a[i] operation_count += 1 break return operation_count t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) print(min_operations(n, a)) ``` 1. 注意输入数据的范围,尤其是序列长度 `n` 和数字的取值范围。 2. 对于处理相同数字段删除操作时,要准确判断起始和结束位置。 3. 交换数字的操作要确保能找到合适的位置进行交换。 [2024-12-21 15:27:24 | AI写代码神器 | 372点数解答]