当前位置:网站首页>1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]
1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]
2022-07-03 01:06:00 【White speed Dragon King's review】

analysis
Give me a list, If the number inside is m Multiples of can be split into m individual x // m, Similarly, if you encounter m Same. x, It can be reduced to mx
ask a Can it become b
Think :a and b If it can be expanded into c, Then there must be a - > c -> b( Because shrinking and releasing are relative )
So we put a and b Just expand , But if there is no brain expansion, it will explode memory
So we can record the same continuous number , Use a two-dimensional representation , And then look at it [-1] Of num Whether it is the same as the current one
If yes, add [-1] Otherwise append([num, cnt])
ac code
import sys
input = sys.stdin.readline
def expand(lst, m):
c = []
for num in lst:
cnt = 1
while num % m == 0:
num //= m
cnt *= m
if len(c) == 0:
c.append([num, cnt])
elif c[-1][0] == num:
c[-1][1] += cnt
else:
c.append([num, cnt])
return c
for _ in range(int(input())):
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
k = int(input())
b = list(map(int, input().split()))
# op1 and op2 are reversible
# if a and b can both expand to c(mid state)
# then a -> c -> b
a = expand(a, m)
b = expand(b, m)
#print(a)
#print(b)
if a == b:
print('Yes')
else:
print('No')
summary
Thinking questions + a become b We'll consider whether we can a and b All become c Then the allowed operation is reversible + Optimize storage ( Record the same number of consecutive occurrences )
边栏推荐
- leetcode-871:最低加油次数
- Illustrated network: what is virtual router redundancy protocol VRRP?
- Arduino开发之按键检测与正弦信号输出
- leetcode-2280:表示一个折线图的最少线段数
- Solve the cache problem of reactnative using WebView
- 【AutoSAR 五 方法论】
- 465. DFS backtracking of optimal bill balance
- In the first half of 2022, there are 10 worth seeing, and each sentence can bring you strength!
- lex && yacc && bison && flex 配置的问题
- 全志A40i/T3如何通过SPI转CAN
猜你喜欢

Assets, vulnerabilities, threats and events of the four elements of safe operation

测试右移:线上质量监控 ELK 实战

Arduino开发之按键检测与正弦信号输出

Sentry developer contribution Guide - configure pycharm

Reading and writing speed of Reza rz/g2l arm development board storage and network measurement

安全运营四要素之资产、脆弱性、威胁和事件
[AUTOSAR five methodology]

excel表格计算时间日期的差值,并转化为分钟数

【AutoSAR 十二 模式管理】

有向图的强连通分量
随机推荐
The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
1.12 - Instructions
tail -f 、tail -F、tailf的区别
Unity learns from spaceshooter to record the difference between fixedupdate and update in unity for the second time
Leetcode-224: basic calculator
Leetcode-871: minimum refueling times
2022 list of manufacturers of Chinese 3D vision enterprises (guided positioning and sorting scenes)
Merge K sorted linked lists
【AutoSAR 四 BSW概述】
百度智能云牵头打造智能云综合标准化平台
mysql 多表联合删除
【AutoSAR 十二 模式管理】
[daily training] 871 Minimum refueling times
The difference between relational database and non relational database
异步、邮件、定时三大任务
1.11 - bus
[AUTOSAR five methodology]
用Go+绘制爱心给心爱的她表白
瑞萨RZ/G2L 处理器简介|框架图|功耗|原理图及硬件设计指南
Thread start and priority