当前位置:网站首页>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)
總結
排序 + 模擬
边栏推荐
- Red hat install kernel header file
- Input of native applet switches between text and password types
- JVM the truth you need to know
- nVisual网络可视化
- async / await
- SAP webservice 测试出现404 Not found Service cannot be reached
- MySQL-CentOS7通过YUM安装MySQL
- ForkJoin最全详解(从原理设计到使用图解)
- Go language context explanation
- Things about data storage 2
猜你喜欢
产业金融3.0:“疏通血管”的金融科技
C#可空类型
Industrial Finance 3.0: financial technology of "dredging blood vessels"
什么是消息队列?
SAP webservice 测试出现404 Not found Service cannot be reached
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
Harmonyos practice - Introduction to development, analysis of atomized services
【日常训练--腾讯精选50】235. 二叉搜索树的最近公共祖先
力扣102题:二叉树的层序遍历
Digital IC interview summary (interview experience sharing of large manufacturers)
随机推荐
EMMC打印cqhci: timeout for tag 10提示分析与解决
数字IC面试总结(大厂面试经验分享)
SQL Server 2008 各种DateTime的取值范围
Go 語言的 Context 詳解
PTA 天梯赛练习题集 L2-002 链表去重
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
Explication contextuelle du langage Go
Dynamic memory management
How to get free traffic in pinduoduo new store and what links need to be optimized in order to effectively improve the free traffic in the store
拼多多新店如何获取免费流量,需要从哪些环节去优化,才能有效提升店内免费流量
C nullable type
Pytorch builds neural network to predict temperature
Five core elements of architecture design
OpenSergo 即将发布 v1alpha1,丰富全链路异构架构的服务治理能力
【日常训练--腾讯精选50】235. 二叉搜索树的最近公共祖先
SQLSTATE[HY000][1130] Host ‘host. docker. internal‘ is not allowed to connect to this MySQL server
成为资深IC设计工程师的十个阶段,现在的你在哪个阶段 ?
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用shap决策图结合LightGBM模型实现异常值检测案例之详细攻略
爬虫练习题(三)
Interview skills of software testing