当前位置:网站首页>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 )
边栏推荐
- Lex & yacc & bison & flex configuration problems
- KingbaseES ALTER TABLE 中 USING 子句的用法
- [daily training] 871 Minimum refueling times
- leetcode-849:到最近的人的最大距离
- 1038 Recover the Smallest Number
- excel表格计算时间日期的差值,并转化为分钟数
- First hand evaluation of Reza electronics rz/g2l development board
- Correctly distinguish the similarities and differences among API, rest API, restful API and web service
- FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟
- Tensorflow 2. Chapter 15 of X (keras) source code explanation: migration learning and fine tuning
猜你喜欢
![[AUTOSAR 11 communication related mechanism]](/img/bf/834b0fad3a3e5bd9c1be04ba150f98.png)
[AUTOSAR 11 communication related mechanism]

(C语言)数据的存储

瑞萨RZ/G2L 处理器简介|框架图|功耗|原理图及硬件设计指南

12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet

excel IF公式判断两列是否相同
![[AUTOSAR + IO Architecture]](/img/cf/9ea42b50bed298c0546764b63bd957.png)
[AUTOSAR + IO Architecture]

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

无向图的割点

Lu Zhe, chief scientist of Shiping information: building data and personnel centered security capabilities

Data analysis, thinking, law breaking and professional knowledge -- analysis method (I)
随机推荐
【AutoSAR 四 BSW概述】
1038 Recover the Smallest Number
[AUTOSAR 11 communication related mechanism]
链表内指定区间反转
【AutoSAR 二 AppL概述】
Win10 can't be installed in many ways Problems with NET3.5
Correctly distinguish the similarities and differences among API, rest API, restful API and web service
Machine learning: numpy version linear regression predicts Boston house prices
1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
leetcode-241:为运算表达式设计优先级
What is needed to develop a domestic arm intelligent edge computing gateway
深度剖析数据在内存中的存储
链表中的节点每k个一组翻转
Leetcode-2115: find all the dishes that can be made from the given raw materials
leetcode-2280:表示一个折线图的最少线段数
matlab查找某一行或者某一列在矩阵中的位置
Initial order of pointer (basic)
leetcode-849:到最近的人的最大距离
Leetcode-224: basic calculator
[overview of AUTOSAR four BSW]