当前位置:网站首页>cf:C. Column Swapping【排序 + 模拟】
cf:C. Column Swapping【排序 + 模拟】
2022-07-07 00:37:00 【白速龙王的回眸】
分析
记录每一行不满足排序的位置
如果大于三个直接凉凉
然后用个set记录需要换的(l,r)
如果大于1个凉凉
然后再判断每个行的l r必须满足a[l] < a[r]
否则凉凉
ac code
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, m = list(map(int, input().split()))
grid = [[0] * m for _ in range(n)]
for i in range(n):
grid[i] = list(map(int, input().split()))
flag = True
mustChanges = set()
for i in range(n):
lst = []
temp = sorted(grid[i])
for j in range(m):
if temp[j] != grid[i][j]:
lst.append(j)
if len(lst) > 2:
flag = False
break
elif len(lst) == 2:
mustChanges.add((lst[0], lst[1]))
if len(mustChanges) >= 2:
flag = False
break
if not flag:
print(-1)
else:
if len(mustChanges) == 0:
print(1, 1)
else:
l, r = list(mustChanges)[0]
flag = True
for i in range(n):
if grid[i][l] < grid[i][r]:
flag = False
break
if flag:
print(l + 1, r + 1)
else:
print(-1)
总结
排序 + 模拟
边栏推荐
- 搞懂fastjson 对泛型的反序列化原理
- 盘点国内有哪些EDA公司?
- SQL query: subtract the previous row from the next row and make corresponding calculations
- Add salt and pepper noise or Gaussian noise to the picture
- 消息队列:重复消息如何处理?
- Web authentication API compatible version information
- Interview questions and salary and welfare of Shanghai byte
- What is dependency injection (DI)
- C#可空类型
- SAP ABAP BDC (batch data communication) -018
猜你喜欢
bat 批示处理详解
Digital IC interview summary (interview experience sharing of large manufacturers)
JVM the truth you need to know
2pc of distributed transaction solution
Randomly generate session_ id
随机生成session_id
上海字节面试问题及薪资福利
sql查询:将下一行减去上一行,并做相应的计算
Paper reading [MM21 pre training for video understanding challenge:video captioning with pre training techniqu]
English grammar_ Noun possessive
随机推荐
关于服装ERP,你知道多少?
Pytorch builds neural network to predict temperature
Web authentication API compatible version information
How much do you know about clothing ERP?
Message queue: how to handle repeated messages?
Add salt and pepper noise or Gaussian noise to the picture
STM32按键状态机2——状态简化与增加长按功能
async / await
Five core elements of architecture design
R语言【逻辑控制】【数学运算】
TCC of distributed transaction solutions
Digital IC interview summary (interview experience sharing of large manufacturers)
Flink SQL realizes reading and writing redis and dynamically generates hset key
Distributed global ID generation scheme
Modes of optical fiber - single mode and multimode
Educational Codeforces Round 22 B. The Golden Age
Lombok plug-in
Message queuing: how to ensure that messages are not lost
Interview skills of software testing
Flinksql 读写pgsql