当前位置:网站首页>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)
总结
排序 + 模拟
边栏推荐
- Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
- 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
- Harmonyos practice - Introduction to development, analysis of atomized services
- I didn't know it until I graduated -- the principle of HowNet duplication check and examples of weight reduction
- Paper reading [open book video captioning with retrieve copy generate network]
- [reading of the paper] a multi branch hybrid transformer network for channel terminal cell segmentation
- Distributed global ID generation scheme
- Web authentication API compatible version information
- Paper reading [semantic tag enlarged xlnv model for video captioning]
- nVisual网络可视化
猜你喜欢

EMMC打印cqhci: timeout for tag 10提示分析与解决
![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 即将发布 v1alpha1,丰富全链路异构架构的服务治理能力

What are the common message queues?

WEB架构设计过程

【日常训练--腾讯精选50】235. 二叉搜索树的最近公共祖先

Modes of optical fiber - single mode and multimode

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

Realize GDB remote debugging function between different network segments

SAP webservice 测试出现404 Not found Service cannot be reached
随机推荐
SAP ABAP BDC(批量数据通信)-018
zabbix_ Get test database failed
产业金融3.0:“疏通血管”的金融科技
pytorch_ 01 automatic derivation mechanism
Web authentication API compatible version information
What is make makefile cmake qmake and what is the difference?
《ClickHouse原理解析与应用实践》读书笔记(6)
WEB架构设计过程
谈fpga和asic的区别
[shell] clean up nohup Out file
Classic questions about data storage
Interview skills of software testing
Reading notes of Clickhouse principle analysis and Application Practice (6)
PTA 天梯赛练习题集 L2-004 搜索树判断
make makefile cmake qmake都是什么,有什么区别?
Realize GDB remote debugging function between different network segments
高级程序员必知必会,一文详解MySQL主从同步原理,推荐收藏
随机生成session_id
SAP webservice 测试出现404 Not found Service cannot be reached
拼多多新店如何获取免费流量,需要从哪些环节去优化,才能有效提升店内免费流量