Codeforces Round 855 (Div
Problem - E2 - Unforgivable Curse (hard version)
给定一个初始字符串s和目标字符串t,我们可以对字符串s进行以下任意次操作:
对于位置\(i\),如果\(i+k+1<=s.length()\) ,那么就可以交换\(i和k或k+1\)的位置上的字符,即\(swap(s[i],s[k])\ \ or \ \ swap(s[i],s[i+k+1])\)
询问能否通过操作使得字符串s变成字符串t
题解:思维
我们经过模拟后发现,除了不能交换位置的字符之外,其他字符之间可以任意交换,我们只要检查一下在不能交换的位置上s和t字符是否相等,然后对在可以交换的位置上的字符计数即可,因为可能会有不是s原本的字符出现在t中
#include <bits/stdc++.h>
#define Zeoy std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
#define debug(x) cerr << #x << '=' << x << endl
#define all(x) (x).begin(), (x).end()
#define rson id << 1 | 1
#define lson id << 1
#define int long long
#define mpk make_pair
#define endl '\n'
using namespace std;
typedef unsigned long long ULL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-9;
const int N = 2e5 + 10, M = 4e5 + 10;
int n, k;
void solve()
{
cin >> n >> k;
string s, t;
cin >> s >> t;
vector<int> cnt(26, 0);
for (int i = 0; i < n; ++i)
{
if (i - k < 0 && i + k >= n)
{
if (s[i] != t[i])
{
cout << "NO" << endl;
return;
}
}
else
{
cnt[s[i] - 'a']++;
cnt[t[i] - 'a']--;
}
}
for (int i = 0; i < 26; ++i)
{
if (cnt[i] != 0)
{
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
}
signed main(void)
{
Zeoy;
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}
Codeforces Round 855 (Div的更多相关文章
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
随机推荐
- fluent python-chap3-1
class collections.OrderedDict([items]) 返回一个 dict 子类的实例,它具有专门用于重新排列字典顺序的方法. """ move_t ...
- GANF: 用于多时间序列异常检测的图增广归一化流《GRAPH-AUGMENTED NORMALIZING FLOWS FOR ANOMALY DETECTION OF MULTIPLE TIME SERIES》(异常检测、多时间序列、DAG、贝叶斯网络、归一化流)
今天是2022年7月12日,差不多小半个月没看论文了,因为模型一直运行不起来+系统搭建的一塌糊涂,今天干脆摆烂,本咸鱼要去看新的论文了(逃避旧工作,bushi). 对了,我们放暑假了,可是我没放暑假. ...
- SSD-KD:天翼云&清华出品,最新无原始数据的蒸馏研究 | CVPR'24
无数据知识蒸馏能够利用大型教师网络所学到的知识,来增强较小型学生网络的训练,而无需访问原始训练数据,从而避免在实际应用中的隐私.安全和专有风险.在这方面的研究中,现有的方法通常遵循一种反演蒸馏的范式, ...
- mysql 批量有则修改,无则新增
需要为表添加唯一索引 alter table tb_*** add unique index(aa,bb); -- 此条为联合唯一索引INSERT INTO<include refid=&quo ...
- Flutter Web 近期的重要更新
我们的发布重点优先关注在性能.开发者体验以及 Web 集成上 2021 年 3 月 Flutter Web 支持已进入稳定版,那么,下一步是什么? 我们对用户研究发现,有超过 10% 的 Flutte ...
- 课时05:Linux必备系统命令
- Spark集群的安装及高可用配置
spark官网学习文档 Spark集群的安装及高可用配置 前期需求:Hadoop和Scala必须已经安装完成 步骤: ①进入spark下载网站中https://spark.apache.org/dow ...
- urb中几个函数的使用
usb_buffer_alloc(free) 说是为了更好的从名字看出这个函数真实做的事情:DMA coherency linux提供两种方式,来保证使用dma时,内存和硬件cache的一致性: us ...
- iOS文本字数动态展示使用小结
项目开发中经常用到类似这样的功能,文本输入的时候需要动态的显示文本输入字数.这里以多行文本框为例,介绍一下实现方案.核心代码如下 -(void)textViewDidChange:(UITextVie ...
- 04-react的基本:条件渲染
import reactDom from "react-dom" // 条件渲染 if else let loading = false // 写一个函数用于加载 const lo ...