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
标签
数组操作
题意
给定长度为 n 的数组 a 和整数 m. 有以下 2 个操作:
选择 1 个 a[i], 且 a[i] 可以被 m 整除. 将这个 a[i] 替换为 m 个 a[i]/m.
选择长度为 m 的数列, 且 a[i] = a[i+1] = … =a[i+m-1], 将其替换为 1 个 m*a[i].
给定长度为 k 的数组 b, 判断能否在任意次操作后将 a 转化为 b.
思路
发现操作 1 和操作 2 是互逆的, 且 a -> b 等价于 b -> a.
把 a, b 都用操作 2 压缩到最短数列, 然后判断其是否相等即可.
把 a, b 都用操作 1 扩展到最长数列, 然后判断其是否相等即可.
由于扩展后数列过长, 会导致 MLE 或 RE, 只需要记录当前的 a[i] 拓展成 num 个 相同的 val, 将连续相同的 val 合并, 判断合并后的两个数组是否相等.
代码 (我太拉了)
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;#define int long long
const int MAXN=5e4+7;
int n,m,k;struct node{int val,num;};vector<node> a(MAXN),b(MAXN);signed main(){cin.tie(0)->sync_with_stdio(0);int T;cin>>T;while(T--){a.clear();b.clear();cin>>n>>m;int val,lena=0,lenb=0;FOR(i,0,n-1){cin>>val;int num=1;while(val%m==0 and val){num*=m;val/=m;}if(a[lena-1].val==val) a[lena-1].num+=num;else a[lena++]=(node){val,num};}cin>>k;FOR(i,0,k-1){cin>>val;int num=1;while(val%m==0 and val){num*=m;val/=m;}if(b[lenb-1].val==val) b[lenb-1].num+=num;else b[lenb++]=(node){val,num};}int eq=1;if(lena!=lenb) {cout<<"No\n";continue;}FOR(i,0,lena-1){if(a[i].val!=b[i].val or a[i].num!=b[i].num) {eq=0;break;}}if(eq==1) cout<<"Yes\n";else cout<<"No\n";}return 0;
}
Codeforces Global Round 21 C. Fishingprince Plays With Array相关推荐
- Codeforces Global Round 21) C. Fishingprince Plays With Array
文章目录 题意 思路 AC代码 C. Fishingprince Plays With Array 题意 题意:给我们一个含有n个元素的数组a,然后再给我们一个含有k个元素的数组b,我们可以对于任何一 ...
- Codeforces Global Round 21 E. Placing Jinas
Problem - E - Codeforces (Unofficial mirror by Menci) E. Placing Jinas 题目大意:每个点相当于(0,0)到每个点(只能向下和向右走 ...
- Codeforces Global Round 1 晕阙记
Codeforces Global Round 1 晕阙记 我做这场比赛的时候晕得要死.做这三道题做太久了,rating涨不起来啊! A 如果愿意的话你可以看做是膜2意义下的运算,写快速幂等各种膜运算 ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
- Codeforces Global Round 14 F. Phoenix and Earthquake 思维 + 并查集
传送门 文章目录 题意: 思路: 题意: 给你nnn个点,mmm条边,限制xxx,每个点都有沥青aia_iai,定义合并两个点即两点之间有边且au+av≥xa_u+a_v\ge xau+av≥x ...
- Codeforces Global Round 1
Codeforces Global Round 1 题解:The Editorial of the First Codeforces Global Round A:其实mod 2计算一下就行了 B:删 ...
- 【Codeforces Global Round 23】B. Rebellion
Codeforces Global Round 23中B. Rebellion Codeforces比赛记录 文章目录 题目链接: 一.B. Rebellion 题目意思: 上思路: 总结 B. Re ...
- Codeforces Global Round 4-D. Prime Graph(伯特兰-切比雪夫定理)
题目:Codeforces Global Round 4-D. Prime Graph 题意:给出n(顶点的个数),要求所得图满足: 1.无平行边和自环 2.边的总数是个质数 3.每个点的度(也就是点 ...
- codeforces global round 23
constest :codeforces global round 23 contest time:2022.10.16 contest grade: 2800 contest rating chan ...
最新文章
- docker镜像指定安装源_Docker 安装与镜像
- iptables实现路由转发
- 3、spring注解注入
- python安装准备_Python安装准备
- 使用eclipse开发Java web应用
- html canvas直线进度条,js+HTML5 canvas 实现简单的加载条(进度条)功能示例
- 百度人脸识别 人脸识别模型_当我说人脸识别很容易时,他们笑了。 但是可以。...
- 人工智能学习书单推荐
- 使用valgrind检查cache命中率
- 华硕主板前置音频设置
- 企业生产计划排产该如何制定
- 清理掉Win10“另存为“和“此电脑“里3D对象、视频、图片、文档、下载、音乐、桌面
- BN和Dropout在训练和测试时的差别
- Linux就业技术指导(四):企业CDN缓存加速原理解密
- chareter oracle,Oracle数据库的操作程序.pdf-汇文网
- 数据看板--日报、周报、月报
- 写高效的java代码
- win10环境下配置Gradle
- 外部地址是什么意思_NAT网络地址转换
- 《计算机网络——自顶向下方法》学习笔记——应用层