当前位置:网站首页>Cf:c. column swapping [sort + simulate]
Cf:c. column swapping [sort + simulate]
2022-07-07 05:56:00 【White speed Dragon King's review】
analysis
Record the position of each row that does not meet the sorting
If there are more than three direct coolings
And then use one set Record what needs to be changed (l,r)
If it is greater than 1 Cool
Then judge each row l r Must satisfy a[l] < a[r]
Otherwise it will be cool
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)
summary
Sort + simulation
边栏推荐
- 牙齿干细胞的存储问题(未完待续)
- Bat instruction processing details
- What is dependency injection (DI)
- AI face editor makes Lena smile
- Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)
- Lombok plug-in
- SQLSTATE[HY000][1130] Host ‘host. docker. internal‘ is not allowed to connect to this MySQL server
- TCC of distributed transaction solutions
- I didn't know it until I graduated -- the principle of HowNet duplication check and examples of weight reduction
- Win configuration PM2 boot auto start node project
猜你喜欢
SAP Spartacus checkout 流程的扩展(extend)实现介绍
Web architecture design process
判断文件是否为DICOM文件
什么是消息队列?
AI人脸编辑让Lena微笑
Realize GDB remote debugging function between different network segments
SQLSTATE[HY000][1130] Host ‘host. docker. internal‘ is not allowed to connect to this MySQL server
一个简单的代数问题的求解
搞懂fastjson 对泛型的反序列化原理
PowerPivot——DAX(函数)
随机推荐
mac版php装xdebug环境(m1版)
Dynamic memory management
上海字节面试问题及薪资福利
话说SQLyog欺骗了我!
cf:C. Column Swapping【排序 + 模拟】
盘点国内有哪些EDA公司?
Interview skills of software testing
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
SAP ABAP BDC(批量数据通信)-018
随机生成session_id
软件测试面试技巧
判断文件是否为DICOM文件
EMMC print cqhci: timeout for tag 10 prompt analysis and solution
Web authentication API compatible version information
三级菜单数据实现,实现嵌套三级菜单数据
关于服装ERP,你知道多少?
980. 不同路径 III DFS
STM32按键状态机2——状态简化与增加长按功能
Différenciation et introduction des services groupés, distribués et microservices
bat 批示处理详解