当前位置:网站首页>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)
总结
排序 + 模拟
边栏推荐
- What is make makefile cmake qmake and what is the difference?
- 集群、分布式、微服務的區別和介紹
- The 2022 China low / no code Market Research and model selection evaluation report was released
- Digital IC interview summary (interview experience sharing of large manufacturers)
- ForkJoin最全详解(从原理设计到使用图解)
- What is dependency injection (DI)
- Lombok plug-in
- 《2022中国低/无代码市场研究及选型评估报告》发布
- How to get free traffic in pinduoduo new store and what links need to be optimized in order to effectively improve the free traffic in the store
- Three level menu data implementation, nested three-level menu data
猜你喜欢

目标检测中的损失函数与正负样本分配:RetinaNet与Focal loss

Simple case of SSM framework

三级菜单数据实现,实现嵌套三级菜单数据

消息队列:如何确保消息不会丢失

得物客服一站式工作台卡顿优化之路
![Paper reading [open book video captioning with retrieve copy generate network]](/img/13/12567c8c2cea2b2a32051535389785.png)
Paper reading [open book video captioning with retrieve copy generate network]

Opensergo is about to release v1alpha1, which will enrich the service governance capabilities of the full link heterogeneous architecture

JVM the truth you need to know

Sidecar mode

Lombok plug-in
随机推荐
Hcip eighth operation
Message queue: how to handle repeated messages?
zabbix_ Get test database failed
【已解决】记一次EasyExcel的报错【读取xls文件时全表读不报错,指定sheet名读取报错】
[solved] record an error in easyexcel [when reading the XLS file, no error will be reported when reading the whole table, and an error will be reported when reading the specified sheet name]
如果不知道这4种缓存模式,敢说懂缓存吗?
原生小程序 之 input切换 text与password类型
[daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree
《HarmonyOS实战—入门到开发,浅析原子化服务》
Win configuration PM2 boot auto start node project
SQLSTATE[HY000][1130] Host ‘host. docker. internal‘ is not allowed to connect to this MySQL server
OpenSergo 即将发布 v1alpha1,丰富全链路异构架构的服务治理能力
Web architecture design process
PTA 天梯赛练习题集 L2-003 月饼 测试点2,测试点3分析
消息队列:如何确保消息不会丢失
Nodejs get client IP
How to get free traffic in pinduoduo new store and what links need to be optimized in order to effectively improve the free traffic in the store
【Shell】清理nohup.out文件
驱动开发中platform设备驱动架构详解
MySQL-CentOS7通过YUM安装MySQL