当前位置:网站首页>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
边栏推荐
- Message queuing: how to ensure that messages are not lost
- 架构设计的五个核心要素
- Loss function and positive and negative sample allocation in target detection: retinanet and focal loss
- PowerPivot——DAX(函数)
- Reptile exercises (III)
- Introduction to distributed transactions
- 980. 不同路径 III DFS
- STM32 key state machine 2 - state simplification and long press function addition
- TCC of distributed transaction solutions
- 力扣102题:二叉树的层序遍历
猜你喜欢

Why does the data center need a set of infrastructure visual management system

集群、分布式、微服務的區別和介紹

Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)

Reptile exercises (III)

数据中心为什么需要一套基础设施可视化管理系统

mac版php装xdebug环境(m1版)

EMMC print cqhci: timeout for tag 10 prompt analysis and solution

Sidecar mode

苹果cms V10模板/MXone Pro自适应影视电影网站模板

What is message queuing?
随机推荐
Flask1.1.4 Werkzeug1.0.1 源碼分析:啟動流程
R语言【逻辑控制】【数学运算】
SQLSTATE[HY000][1130] Host ‘host. docker. internal‘ is not allowed to connect to this MySQL server
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
CTFshow--常用姿势
Question 102: sequence traversal of binary tree
Go 語言的 Context 詳解
Modes of optical fiber - single mode and multimode
TCC of distributed transaction solutions
404 not found service cannot be reached in SAP WebService test
Mysql-centos7 install MySQL through yum
EMMC print cqhci: timeout for tag 10 prompt analysis and solution
产业金融3.0:“疏通血管”的金融科技
make makefile cmake qmake都是什么,有什么区别?
Get the way to optimize the one-stop worktable of customer service
谈fpga和asic的区别
Loss function and positive and negative sample allocation in target detection: retinanet and focal loss
Flask1.1.4 werkzeug1.0.1 source code analysis: start the process
Add salt and pepper noise or Gaussian noise to the picture
绕过open_basedir