当前位置:网站首页>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)
总结
排序 + 模拟
边栏推荐
- Bat instruction processing details
- zabbix_get测试数据库失败
- Classic questions about data storage
- 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
- Web authentication API compatible version information
- Red Hat安装内核头文件
- Type de texte de commutation d'entrée et de mot de passe de l'applet natif
- 线性回归
- [paper reading] semi supervised left atrium segmentation with mutual consistency training
- nVisual网络可视化
猜你喜欢
随机推荐
In memory, I moved from CSDN to blog park!
C#可空类型
Flink SQL realizes reading and writing redis and dynamically generates hset key
SQLSTATE[HY000][1130] Host ‘host. docker. internal‘ is not allowed to connect to this MySQL server
Message queue: how to handle repeated messages?
980. 不同路径 III DFS
Hcip seventh operation
An example of multi module collaboration based on NCF
Educational Codeforces Round 22 B. The Golden Age
软件测试面试技巧
力扣102题:二叉树的层序遍历
判断文件是否为DICOM文件
[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]
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实战—入门到开发,浅析原子化服务》
数字IC面试总结(大厂面试经验分享)
Message queuing: how to ensure that messages are not lost
Why does the data center need a set of infrastructure visual management system
EMMC print cqhci: timeout for tag 10 prompt analysis and solution
Flask1.1.4 werkzeug1.0.1 source code analysis: start the process








