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为还需要的蜡烛数, ...
随机推荐
- 技术解析 | ZEGO 移动端超分辨率技术
即构超分追求:速度更快.效果更好.码率更低.机型更广. 超分辨率(Super Resolution, SR)是从给定的低分辨率(Low Resolution, LR)图像中恢复高分辨率(High ...
- 知识点考古:php5的面向对象学习笔记
闲来无事翻看以前收藏的资料,考古到保存的这篇文章对php的OOP的整理还很系统.原链接已经打不开(http://www.cublog.cn/u/17686/showart.php?id=146562) ...
- Go runtime 调度器精讲(三):main goroutine 创建
原创文章,欢迎转载,转载请注明出处,谢谢. 0. 前言 回顾下 上一讲 的内容.主线程 m0 蓄势待发,准备干活.g0 为 m0 提供了执行环境,P 和 m0 绑定,为 m0 提供活,也就是 goro ...
- java_day1_认识计算机,java环境,Java关键字、标识符、注释
一.认识计算机 1.组成: 硬件:cpu,内存,显卡,... 软件: 系统软件:WPS, wegame, steam, IDEA,..... 应用软件:WPS, wegame, steam, IDEA ...
- PasteForm最佳CRUD实践,实际案例PasteTemplate详解之管理前端的代码(二)
之前的文章说了,使用反射和ABPvNext的Dto实现用后端控制前端以实现最佳CRUD实践! 相信看过一的已经了解了这个PasteForm是如何实现的了,本文来看下具体如何实现的 表格页面的实现 打开 ...
- 【赵渝强老师】删除表和Oracle的回收站
一.Oracle的Drop Table语句 首先,我们来看一下Oracle Drop Table的语法格式. 解释一下里面的参数: schema Schema表示方案名称,这里可以理解为用户名,缺省为 ...
- LeetCode 1388. Pizza With 3n Slices(3n 块披萨)(DP)
给你一个披萨,它由 3n 块不同大小的部分组成,现在你和你的朋友们需要按照如下规则来分披萨: 你挑选 任意 一块披萨.Alice 将会挑选你所选择的披萨逆时针方向的下一块披萨.Bob 将会挑选你所选择 ...
- Salesforce AI Specialist篇之 Prompt Builder
本篇参考: https://salesforce.vidyard.com/watch/UUAxcUfHYGAxH3D9wV1RxJ https://help.salesforce.com/s/arti ...
- Serilog文档翻译系列(七) - 应用设置、调试和诊断、开发接收器
01.应用设置 Serilog 支持在 App.config 和 Web.config 文件中使用简单的 配置语法,以设置最低日志级别.为事件添加额外属性以及控制日志输出. Serilog 主要通过代 ...
- 【解决方案】基于数据库驱动的自定义 TypeHandler 处理器
目录 前言 一.TypeHandler 简介 1.1转换步骤 1.2转换规则 二.JSON 转换 三.枚举转换 四.文章小结 前言 笔者在最近的项目开发中,频繁地遇到了 Java 类型与 JDBC 类 ...