当前位置:网站首页>cf:C. Column Swapping【排序 + 模拟】
cf:C. Column Swapping【排序 + 模拟】
2022-07-07 00:37: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)
总结
排序 + 模拟
边栏推荐
- [reading of the paper] a multi branch hybrid transformer network for channel terminal cell segmentation
- Input of native applet switches between text and password types
- Flinksql 读写pgsql
- pytorch_ 01 automatic derivation mechanism
- 【已解决】记一次EasyExcel的报错【读取xls文件时全表读不报错,指定sheet名读取报错】
- Three level menu data implementation, nested three-level menu data
- Add salt and pepper noise or Gaussian noise to the picture
- zabbix_get测试数据库失败
- STM32按键状态机2——状态简化与增加长按功能
- Get the way to optimize the one-stop worktable of customer service
猜你喜欢
上海字节面试问题及薪资福利
消息队列:如何确保消息不会丢失
Nvisual network visualization
R language [logic control] [mathematical operation]
Flink SQL realizes reading and writing redis and dynamically generates hset key
PTA ladder game exercise set l2-004 search tree judgment
《HarmonyOS实战—入门到开发,浅析原子化服务》
如何提高网站权重
Différenciation et introduction des services groupés, distribués et microservices
【日常训练--腾讯精选50】235. 二叉搜索树的最近公共祖先
随机推荐
yarn入门(一篇就够了)
Common skills and understanding of SQL optimization
牙齿干细胞的存储问题(未完待续)
如果不知道这4种缓存模式,敢说懂缓存吗?
[云原生]微服务架构是什么?
ML之shap:基于adult人口普查收入二分类预测数据集(预测年收入是否超过50k)利用shap决策图结合LightGBM模型实现异常值检测案例之详细攻略
Pytorch builds neural network to predict temperature
"Multimodal" concept
EMMC print cqhci: timeout for tag 10 prompt analysis and solution
Go 語言的 Context 詳解
What is make makefile cmake qmake and what is the difference?
Message queue: how to handle repeated messages?
[daily training -- Tencent selected 50] 235 Nearest common ancestor of binary search tree
SQL query: subtract the previous row from the next row and make corresponding calculations
Web Authentication API兼容版本信息
Harmonyos practice - Introduction to development, analysis of atomized services
消息队列:如何确保消息不会丢失
How to improve website weight
SAP webservice 测试出现404 Not found Service cannot be reached
Unity keeps the camera behind and above the player