1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
分析
给一个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.readlinedef expand(lst, m):c = []for num in lst:cnt = 1while num % m == 0:num //= mcnt *= mif len(c) == 0:c.append([num, cnt])elif c[-1][0] == num:c[-1][1] += cntelse:c.append([num, cnt])return cfor _ 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 -> ba = expand(a, m)b = expand(b, m)#print(a)#print(b)if a == b:print('Yes')else:print('No')
总结
思维题 + a变成b 我们考虑能不能a和b都变成c 然后允许的操作是具有可逆性的 + 优化存储(记录连续出现的相同的个数)
1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】相关推荐
- Fishingprince Plays With Array(思维/数学/实现)
Fishingprince Plays With Array 传送门 Problem - 1696C - Codeforces 思路 把a和b数组不断拓展,直到不能拓展为止,记不能再拓展的数值为最小元 ...
- Codeforces Global Round 21) C. Fishingprince Plays With Array
文章目录 题意 思路 AC代码 C. Fishingprince Plays With Array 题意 题意:给我们一个含有n个元素的数组a,然后再给我们一个含有k个元素的数组b,我们可以对于任何一 ...
- C. Fishingprince Plays With Array
Problem - C - Codeforces 题意就是给一个数m,有两种操作,看看能否从序列a到序列b 操作1:如果ai能整除m,那一个数ai变成m个ai/m(其他数字及其位置保持不变) 操作2: ...
- Codeforces Global Round 21 C. Fishingprince Plays With Array
https://codeforces.com/contest/1696/problem/C st1=21:57, ed1=22:10 st2=22:25, ed2=null 标签 数组操作 题意 给定 ...
- Codeforces1696 C. Fishingprince Plays With Array
首先将两个数组切分到不能切分为止,然后判断是否相等,数组的表示经过了一定的压缩. rust: #[allow(unused_imports)] use std::cmp::{min,max}; use ...
- Codeforces 1077B Disturbed People(思维题)
Codeforces 1077B Disturbed People(思维题) There is a house with nn flats situated on the main street of ...
- codeforces 有意思的思维题 1 ~ 15
codeforces 思维题 1.给定数组,求满足i < j and ai * aj = i + j的数对数量 2.第 i 步向前跳 i 步或后退 1 步 3.给两个点,求正方形的另两个点 4. ...
- little w and Soda(思维题)
链接:https://ac.nowcoder.com/acm/contest/297/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
最新文章
- DevExpress的TextEdit限制输入内容的格式,比如只能输入数字
- windows/linux服务器上java使用openoffice将word文档转换为PDF(亲测可用)
- PHOTOSHOP中3D下拉菜单为灰色如何设置
- Java Mission Control 5.2终于来了! 欢迎7u40!
- pythongui显示图片_opencv2.4.13+python2.7学习笔记--opencv中的Gui特性--图片:读图像,显示图像,保存图像...
- linq To DataTable
- M1芯片电脑出现重装系统Bug,教你如何「正确」重装macOS
- React:基础知识学习
- dh参数逆运动学_干货 | 运动学好像够用了,我们为什么还需要动力学
- Vue-购物车简单案例
- 理解python 文件首行(Shebang)
- 数据库基本操作和常用命令
- C# 关于浏览器——WebKit篇
- 怎么计算java对象的大小?
- 建网站如何选择服务器
- gem意思_邓紫棋为什么叫GEM 每次改名都有意义
- windows下如何配置AWS进行深度学习
- 【第36题】JAVA高级技术-对象克隆5(几种深克隆效率比较)
- Python与人工神经网络(2)——使用神经网络识别手写图像
- RDD编程初级实践-课程论文