当前位置:网站首页>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
边栏推荐
- 爬虫练习题(三)
- 【SQL实战】一条SQL统计全国各地疫情分布情况
- WEB架构设计过程
- Flinksql read / write PgSQL
- 苹果cms V10模板/MXone Pro自适应影视电影网站模板
- Data storage 3
- Bbox regression loss function in target detection -l2, smooth L1, IOU, giou, Diou, ciou, focal eiou, alpha IOU, Siou
- STM32 key state machine 2 - state simplification and long press function addition
- What is message queuing?
- Input of native applet switches between text and password types
猜你喜欢
Reading notes of Clickhouse principle analysis and Application Practice (6)
Nvisual network visualization
SAP webservice 测试出现404 Not found Service cannot be reached
[cloud native] what is the microservice architecture?
AI face editor makes Lena smile
What are the common message queues?
Hcip seventh operation
什么是消息队列?
SQLSTATE[HY000][1130] Host ‘host. docker. internal‘ is not allowed to connect to this MySQL server
搞懂fastjson 对泛型的反序列化原理
随机推荐
Introduction to distributed transactions
搞懂fastjson 对泛型的反序列化原理
Reptile exercises (III)
【SQL实战】一条SQL统计全国各地疫情分布情况
原生小程序 之 input切换 text与password类型
make makefile cmake qmake都是什么,有什么区别?
async / await
Type de texte de commutation d'entrée et de mot de passe de l'applet natif
Simple case of SSM framework
目标检测中的损失函数与正负样本分配:RetinaNet与Focal loss
《2022中国低/无代码市场研究及选型评估报告》发布
数字IC面试总结(大厂面试经验分享)
Web authentication API compatible version information
Get the way to optimize the one-stop worktable of customer service
The 2022 China low / no code Market Research and model selection evaluation report was released
Explication contextuelle du langage Go
Bat instruction processing details
Web Authentication API兼容版本信息
PowerPivot - DAX (function)
An example of multi module collaboration based on NCF