当前位置:网站首页>1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
2022-07-03 00:46:00 【白速龙王的回眸】
分析
给一个list,里面的数如果是m的倍数可以拆成m个x // m,同样的如果遇到m个一样的x,可以缩成mx
问a能不能经过若干这两个操作变成b
思维点:a和b如果能同时扩展成c,那么必定有a - > c -> b(因为缩和放是相对的)
因此我们把a和b扩展即可,但是如果无脑扩展会爆memory
于是我们记录相同的连续的个数即可,用一个二维的表示,然后看看[-1]的num和目前是否相同即可
是的话加到[-1]否则的话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')
总结
思维题 + a变成b 我们考虑能不能a和b都变成c 然后允许的操作是具有可逆性的 + 优化存储(记录连续出现的相同的个数)
边栏推荐
- Sentry developer contribution Guide - configure pycharm
- [daily training] 871 Minimum refueling times
- 【AutoSAR 三 RTE概述】
- 有向图的强连通分量
- 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
- AEM: Nanlin fan Ben et al. - plant rhizosphere growth promoting bacteria control soybean blight
- leetcode-2115:从给定原材料中找到所有可以做出的菜
- 利亚德:Micro LED 产品消费端首先针对 100 英寸以上电视,现阶段进入更小尺寸还有难度
- Vulkan performance and refinement
- 瑞萨电子RZ/G2L开发板上手评测
猜你喜欢
[AUTOSAR + IO Architecture]
Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
世平信息首席科学家吕喆:构建以数据和人员为中心的安全能力
Is there a free text to speech tool to help recommend?
【AutoSAR 六 描述文件】
Rust string slicing, structs, and enumeration classes
Illustrated network: what is virtual router redundancy protocol VRRP?
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
Teach you JDBC hand in hand -- structure separation
[C language] branch and loop statements (Part 1)
随机推荐
Leetcode-1964: find the longest effective obstacle race route to each position
无向图的割点
Initial order of pointer (basic)
Illustrated network: what is virtual router redundancy protocol VRRP?
FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟
Inversion de l'intervalle spécifié dans la liste des liens
mysql 多表联合删除
解决ReactNative使用webView存在缓存问题
FPGA - 7 Series FPGA internal structure clocking -04- multi area clock
[AUTOSAR five methodology]
465. 最优账单平衡 DFS 回溯
【小程序项目开发-- 京东商城】uni-app之自定义搜索组件(中)-- 搜索建议
2022 list of manufacturers of Chinese 3D vision enterprises (guided positioning and sorting scenes)
tail -f 、tail -F、tailf的区别
[love crash] neglected details of gibaro
1.11 - bus
Vulkan practice first bullet
1.12 - Instructions
基于ARM RK3568的红外热成像体温检测系统
[AUTOSAR eight OS]