当前位置:网站首页>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 然后允许的操作是具有可逆性的 + 优化存储(记录连续出现的相同的个数)
边栏推荐
- [AUTOSAR five methodology]
- In the first half of 2022, there are 10 worth seeing, and each sentence can bring you strength!
- Vulkan practice first bullet
- FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟
- Lu Zhe, chief scientist of Shiping information: building data and personnel centered security capabilities
- The difference between relational database and non relational database
- 解决ReactNative使用webView存在缓存问题
- 1.12 - 指令
- leetcode-224:基本计算器
- excel IF公式判断两列是否相同
猜你喜欢
Arduino开发之按键检测与正弦信号输出
Unity learns from spaceshooter to record the difference between fixedupdate and update in unity for the second time
[love crash] neglected details of gibaro
指针初阶(基础)
世平信息首席科学家吕喆:构建以数据和人员为中心的安全能力
Data analysis, thinking, law breaking and professional knowledge -- analysis method (I)
Rust ownership (very important)
Win10 多种方式解决无法安装.Net3.5的问题
Leetcode-849: maximum distance to the nearest person
【AutoSAR 二 AppL概述】
随机推荐
Arduino开发之按键检测与正弦信号输出
测试右移:线上质量监控 ELK 实战
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
How to systematically learn machine learning
leetcode-2115:从给定原材料中找到所有可以做出的菜
【日常训练】871. 最低加油次数
(C language) data storage
数学建模之线性规划(含MATLAB代码)
百度智能云牵头打造智能云综合标准化平台
Leetcode-224: basic calculator
【AutoSAR 六 描述文件】
In the first half of 2022, there are 10 worth seeing, and each sentence can bring you strength!
Vulkan practice first bullet
[AUTOSAR nine c/s principle Architecture]
瑞萨RZ/G2L ARM开发板存储读写速度与网络实测
RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide
leetcode-241:为运算表达式设计优先级
Several cases of recursive processing organization
Sentry developer contribution Guide - configure pycharm