当前位置:网站首页>C. colonne Swapping [tri + Simulation]
C. colonne Swapping [tri + Simulation]
2022-07-07 05:55:00 【Rétrospective du roi dragon blanc】

Analyse
Notez où chaque ligne ne correspond pas au tri
Si plus de trois refroidissements directs
Et avec unsetLes dossiers doivent être changés(l,r)
Si plus de1Cool.
Et puis on juge chaque lignel rDoit satisfairea[l] < a[r]
Sinon, il fait froid
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)
Résumé
Trier + Simulation
边栏推荐
- 驱动开发中platform设备驱动架构详解
- OpenSergo 即将发布 v1alpha1,丰富全链路异构架构的服务治理能力
- Go language context explanation
- JVM the truth you need to know
- Determine whether the file is a DICOM file
- WEB架构设计过程
- pytorch_ 01 automatic derivation mechanism
- 搞懂fastjson 对泛型的反序列化原理
- Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
- Red Hat安装内核头文件
猜你喜欢

Randomly generate session_ id

ForkJoin最全详解(从原理设计到使用图解)

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

Bat instruction processing details

驱动开发中platform设备驱动架构详解

Realize GDB remote debugging function between different network segments

Get the way to optimize the one-stop worktable of customer service

常用消息队列有哪些?

话说SQLyog欺骗了我!

PTA ladder game exercise set l2-004 search tree judgment
随机推荐
SQL query: subtract the previous row from the next row and make corresponding calculations
目标检测中的BBox 回归损失函数-L2,smooth L1,IoU,GIoU,DIoU,CIoU,Focal-EIoU,Alpha-IoU,SIoU
【日常训练--腾讯精选50】292. Nim 游戏
PTA ladder game exercise set l2-002 linked list de duplication
SAP ABAP BDC(批量数据通信)-018
PTA 天梯赛练习题集 L2-002 链表去重
Red Hat安装内核头文件
三级菜单数据实现,实现嵌套三级菜单数据
Classic questions about data storage
Polynomial locus of order 5
原生小程序 之 input切換 text與password類型
驱动开发中platform设备驱动架构详解
什么是消息队列?
Mybaits multi table query (joint query, nested query)
Web architecture design process
How to improve website weight
EMMC print cqhci: timeout for tag 10 prompt analysis and solution
Add salt and pepper noise or Gaussian noise to the picture
集群、分布式、微服務的區別和介紹
得物客服一站式工作台卡顿优化之路