当前位置:网站首页>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 )
边栏推荐
- 1.11 - bus
- How to systematically learn machine learning
- 正确甄别API、REST API、RESTful API和Web Service之间的异同
- 瑞萨RZ/G2L ARM开发板存储读写速度与网络实测
- Sentry developer contribution Guide - configure pycharm
- 12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
- 无向图的割点
- 【AutoSAR 四 BSW概述】
- [AUTOSAR 11 communication related mechanism]
- [introduction to AUTOSAR seven tool chain]
猜你喜欢
Liad: the consumer end of micro LED products is first targeted at TVs above 100 inches. At this stage, it is still difficult to enter a smaller size
异步、邮件、定时三大任务
(C语言)数据的存储
飞凌搭载TI AM62x的ARM核心板/开发板首发上市,亮相Embedded World 2022
Reading and writing speed of Reza rz/g2l arm development board storage and network measurement
Illustrated network: what is virtual router redundancy protocol VRRP?
File operation io-part2
【AutoSAR 八 OS】
2022 list of manufacturers of Chinese 3D vision enterprises (guided positioning and sorting scenes)
安全运营四要素之资产、脆弱性、威胁和事件
随机推荐
Compare version number
[AUTOSAR XIII NVM]
【AutoSAR 八 OS】
The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
Matlab saves the digital matrix as geospatial data, and the display subscript index must be of positive integer type or logical type. Solve the problem
【案例分享】让新时代教育发展与“数”俱进
Inversion de l'intervalle spécifié dans la liste des liens
安全运营四要素之资产、脆弱性、威胁和事件
Reading and writing speed of Reza rz/g2l arm development board storage and network measurement
[love crash] neglected details of gibaro
指针初阶(基础)
这不平凡的两年,感谢我们一直在一起!
[AUTOSAR nine c/s principle Architecture]
Leetcode-2115: find all the dishes that can be made from the given raw materials
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
[shutter] image component (configure local GIF image resources | load placeholder with local resources)
1038 Recover the Smallest Number
关于Fibonacci数列
1.11 - bus