当前位置:网站首页>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
边栏推荐
- yarn入门(一篇就够了)
- STM32 key state machine 2 - state simplification and long press function addition
- 毕业之后才知道的——知网查重原理以及降重举例
- Hcip seventh operation
- 原生小程序 之 input切换 text与password类型
- 上海字节面试问题及薪资福利
- What are the common message queues?
- Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
- Web architecture design process
- Message queue: how to handle repeated messages?
猜你喜欢
EMMC打印cqhci: timeout for tag 10提示分析与解决
Three level menu data implementation, nested three-level menu data
Introduction to distributed transactions
Modes of optical fiber - single mode and multimode
上海字节面试问题及薪资福利
话说SQLyog欺骗了我!
分布式全局ID生成方案
毕业之后才知道的——知网查重原理以及降重举例
Dynamic memory management
【SQL实战】一条SQL统计全国各地疫情分布情况
随机推荐
Harmonyos practice - Introduction to development, analysis of atomized services
《2022中国低/无代码市场研究及选型评估报告》发布
[云原生]微服务架构是什么?
Reading the paper [sensor enlarged egocentric video captioning with dynamic modal attention]
[cloud native] what is the microservice architecture?
Dynamic memory management
R语言【逻辑控制】【数学运算】
[shell] clean up nohup Out file
牙齿干细胞的存储问题(未完待续)
Loss function and positive and negative sample allocation in target detection: retinanet and focal loss
微信小程序蓝牙连接硬件设备并进行通讯,小程序蓝牙因距离异常断开自动重连,js实现crc校验位
SQLSTATE[HY000][1130] Host ‘host. docker. internal‘ is not allowed to connect to this MySQL server
JVM the truth you need to know
随机生成session_id
Mysql-centos7 install MySQL through yum
【已解决】记一次EasyExcel的报错【读取xls文件时全表读不报错,指定sheet名读取报错】
What is dependency injection (DI)
Lombok plug-in
An example of multi module collaboration based on NCF
盘点国内有哪些EDA公司?