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的更多相关文章

  1. 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 ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

  10. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

随机推荐

  1. DOM & BOM – Input File, Drag & Drop File, File Reader, Blob, ArrayBuffer, File, UTF-8 Encode/Decode, Download File

    前言 之前写过 2 篇关于读写文件和二进制相关的文章 Bit, Byte, ASCII, Unicode, UTF, Base64 和 ASP.NET Core – Byte, Stream, Dir ...

  2. MDC – Work with Framework & Customize

    前言 在 MDC – Material Design, Angular Material, MDC, MWC, Lit 的关系 中, 我有提到基于 MDC 的 Framework 生态有多糟糕. 但它 ...

  3. SqlEs-像使用数据库一样使用Elasticsearch

    SqlEs SqlEs是Elasticsearch的客户端JDBC驱动程序,支持采用sql语法操作Elasticsearch.SqlEs构建在RestHighLevelClient,屏蔽了RestHi ...

  4. [29] CSP模拟2

    A.不相邻集合 考虑值域上连续的段,可以发现连续的长度为 \(x\) 的段的贡献必定为 \(\lceil{\frac{x}{2}}\rceil\) 考虑并查集维护值域连续的段的大小,每次询问求出全部连 ...

  5. Docker基本概念(LXC?镜像、容器、仓库是什么?容器和虚拟机又是什么?)(一)

    学习Docker前,我们有必要了解下Docker的前生LXC(Linux Container). 一.LXC介绍 LXC 可以提供轻量级的虚拟化,用来隔离进程和资源,和我们传统观念中的全虚拟化完全不一 ...

  6. iOS中UIlabel多行文本展示使用小结

    最近在项目开发中遇到了一个新的需求,就是菜单标题最多两行展示,一行展示的标签顶部和两行展示的标签顶部对齐.看到要求后,第一反应是这是什么奇葩的设计,但是没办法谁让别人是产品经理呢.细细思索后,代码如下 ...

  7. 轨道控制器 threejs

    就是一个可以360转动的相机,通过不断的改变相机的参数 然后渲染达到效果. // 引入相机控件  -- 轨道控制器 // console.log('OrbitControls',OrbitContro ...

  8. day01-markdown学习

    markdown学习 标题 两个#号 三级标题 四级标题 字体 hello world!两个*加粗 hello world!一个*斜体 hello world!三个*斜体加粗 hello world! ...

  9. JOI 2018 Final

    A - ストーブ (Stove) 有 \(n\) 个客人将要来访,第 \(i\) 个客人的来访时间为 \([a_i, a_i + 1]\),保证 \(\forall i \in [1, n), a_i ...

  10. 在 Azure CNI 中启用 Calico WireGuard

    作者:Peter Kelly 译者:Wendi Wang 注:本文已取得作者本人的翻译授权! 去年6月,Tigera 宣布首次在 K8s 上支持用于集群内加密传输的开源 VPN - WireGuard ...