当前位置:网站首页>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 )
边栏推荐
- Unity learns from spaceshooter to record the difference between fixedupdate and update in unity for the second time
- Understanding and distinguishing of some noun concepts in adjustment / filtering
- Solve the cache problem of reactnative using WebView
- 465. 最优账单平衡 DFS 回溯
- 1038 Recover the Smallest Number
- Win10 can't be installed in many ways Problems with NET3.5
- 【爱死机】《吉巴罗》被忽略的细节
- matlab查找某一行或者某一列在矩阵中的位置
- Initial order of pointer (basic)
- Leetcode-2280: represents the minimum number of line segments of a line graph
猜你喜欢

Vulkan practice first bullet

FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟

Basic use of sringcloud & use of component Nacos

Key detection and sinusoidal signal output developed by Arduino

excel去除小数点后面的数据,将数字取整

leetcode-849:到最近的人的最大距离

In the first half of 2022, there are 10 worth seeing, and each sentence can bring you strength!

Correctly distinguish the similarities and differences among API, rest API, restful API and web service
![[AUTOSAR VI description document]](/img/3d/1382acbc4054ab218485a12b7b4e6b.png)
[AUTOSAR VI description document]
【AutoSAR 五 方法论】
随机推荐
[overview of AUTOSAR four BSW]
[daily training] 871 Minimum refueling times
Baidu AI Cloud takes the lead in building a comprehensive and standardized platform for smart cloud
Understanding and distinguishing of some noun concepts in adjustment / filtering
Foundations of data science is free to download
Inversion de l'intervalle spécifié dans la liste des liens
基于ARM RK3568的红外热成像体温检测系统
Vulkan is not a "panacea"“
Advanced pointer (I)
[overview of AUTOSAR three RTE]
Leetcode-224: basic calculator
Leetcode-2280: represents the minimum number of line segments of a line graph
Thank you for being together for these extraordinary two years!
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
这不平凡的两年,感谢我们一直在一起!
RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide
飞凌搭载TI AM62x的ARM核心板/开发板首发上市,亮相Embedded World 2022
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
世平信息首席科学家吕喆:构建以数据和人员为中心的安全能力
【AutoSAR 六 描述文件】