当前位置:网站首页>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)
總結
排序 + 模擬
边栏推荐
- 980. Different path III DFS
- TCC of distributed transaction solutions
- Go language context explanation
- 404 not found service cannot be reached in SAP WebService test
- PTA ladder game exercise set l2-002 linked list de duplication
- SQLSTATE[HY000][1130] Host ‘host. docker. internal‘ is not allowed to connect to this MySQL server
- 一个简单的代数问题的求解
- Dynamic memory management
- Mac version PHP installed Xdebug environment (M1 version)
- Reptile exercises (III)
猜你喜欢

PowerPivot——DAX(函数)

Introduction to distributed transactions

随机生成session_id

Differences and introduction of cluster, distributed and microservice
![Reading the paper [sensor enlarged egocentric video captioning with dynamic modal attention]](/img/db/feb719e2715c7b9c669957995e1d83.png)
Reading the paper [sensor enlarged egocentric video captioning with dynamic modal attention]

An example of multi module collaboration based on NCF

常用消息队列有哪些?
![R language [logic control] [mathematical operation]](/img/93/06a306561e3e7cb150d243541cc839.png)
R language [logic control] [mathematical operation]

Distributed global ID generation scheme

驱动开发中platform设备驱动架构详解
随机推荐
一个简单的代数问题的求解
What is message queuing?
Mac version PHP installed Xdebug environment (M1 version)
[cloud native] what is the microservice architecture?
Loss function and positive and negative sample allocation in target detection: retinanet and focal loss
zabbix_ Get test database failed
Message queue: how to deal with message backlog?
Go language context explanation
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
数据中心为什么需要一套基础设施可视化管理系统
【SQL实战】一条SQL统计全国各地疫情分布情况
R language [logic control] [mathematical operation]
An example of multi module collaboration based on NCF
集群、分布式、微服务的区别和介绍
Bbox regression loss function in target detection -l2, smooth L1, IOU, giou, Diou, ciou, focal eiou, alpha IOU, Siou
How much do you know about clothing ERP?
linear regression
Input of native applet switches between text and password types
Explication contextuelle du langage Go
产业金融3.0:“疏通血管”的金融科技