当前位置:网站首页>cf:C. Column Swapping【排序 + 模擬】
cf:C. Column Swapping【排序 + 模擬】
2022-07-07 05:55: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)
總結
排序 + 模擬
边栏推荐
- 数据中心为什么需要一套基础设施可视化管理系统
- Flask1.1.4 Werkzeug1.0.1 源码分析:启动流程
- SQL Server 2008 各种DateTime的取值范围
- Type de texte de commutation d'entrée et de mot de passe de l'applet natif
- 谈fpga和asic的区别
- 集群、分布式、微服务的区别和介绍
- OpenSergo 即将发布 v1alpha1,丰富全链路异构架构的服务治理能力
- EMMC打印cqhci: timeout for tag 10提示分析与解决
- 三级菜单数据实现,实现嵌套三级菜单数据
- make makefile cmake qmake都是什么,有什么区别?
猜你喜欢
随机推荐
[云原生]微服务架构是什么?
《2022中国低/无代码市场研究及选型评估报告》发布
SQL query: subtract the previous row from the next row and make corresponding calculations
Go 语言的 Context 详解
sql查询:将下一行减去上一行,并做相应的计算
AI face editor makes Lena smile
Loss function and positive and negative sample allocation in target detection: retinanet and focal loss
Why does the data center need a set of infrastructure visual management system
Get the way to optimize the one-stop worktable of customer service
得物客服一站式工作台卡顿优化之路
【SQL实战】一条SQL统计全国各地疫情分布情况
Reptile exercises (III)
Wechat applet Bluetooth connects hardware devices and communicates. Applet Bluetooth automatically reconnects due to abnormal distance. JS realizes CRC check bit
随机生成session_id
Mybaits multi table query (joint query, nested query)
R language [logic control] [mathematical operation]
目标检测中的BBox 回归损失函数-L2,smooth L1,IoU,GIoU,DIoU,CIoU,Focal-EIoU,Alpha-IoU,SIoU
Differences and introduction of cluster, distributed and microservice
How much do you know about clothing ERP?
yarn入门(一篇就够了)