# CF1451C String Equality（数学细心分析，万物皆有规律）

## 题目描述

Ashish has two strings aa and bb , each of length nn , and an integer kk . The strings only contain lowercase English letters.

He wants to convert string aa into string bb by performing some (possibly zero) operations on aa .

In one move, he can either

choose an index ii ( 1 \leq i\leq n-11≤i≤n−1 ) and swap a_iai and a_{i+1}ai+1 , or

choose an index ii ( 1 \leq i \leq n-k+11≤i≤n−k+1 ) and if a_i, a_{i+1}, \ldots, a_{i+k-1}ai,ai+1,…,ai+k−1 are all equal to some character cc ( c \neqc= 'z'), replace each one with the next character (c+1)(c+1) , that is, 'a' is replaced by 'b', 'b' is replaced by 'c' and so on.

Note that he can perform any number of operations, and the operations can only be performed on string aa .

Help Ashish determine if it is possible to convert string aa into bb after performing some (possibly zero) operations on it.

## 输入格式

The first line contains a single integer tt ( 1 \leq t \leq 10^51≤t≤105 ) — the number of test cases. The description of each test case is as follows.

The first line of each test case contains two integers nn ( 2 \leq n \leq 10^62≤n≤106 ) and kk ( 1 \leq k \leq n1≤k≤n ).

The second line of each test case contains the string aa of length nn consisting of lowercase English letters.

The third line of each test case contains the string bb of length nn consisting of lowercase English letters.

It is guaranteed that the sum of values nn among all test cases does not exceed 10^6106 .

## 输出格式

For each test case, print "Yes" if Ashish can convert aa into bb after some moves, else print "No".

You may print the letters of the answer in any case (upper or lower).

## 题意翻译

Ashish 会对字符串 aa 进行以下两种操作：

• 选择一个位置  i（ 1≤i≤n−1）并交换  ai 和  ai+1。
• 选择一个位置 i （ 1≤i≤n−k+1），满足 ai,ai+1,…,ai+k−1 都等于某个字符 c （ c！='z'），把 ai,ai+1,…,ai+k−1 都变成 (c+1)。

## 输入输出样例

4

3 3

abc

bcd

4 2

abba

azza

2 1

zz

aa

6 2

aaabba

ddddcc

No

Yes

No

Yes

        rep(i,1,n) aa[a[i]-'a']++;
rep(i,1,n) aa[b[i]-'a']--;
int now=0;bool flg=1;
per(i,25,0) {
now-=aa[i];
if(now<0||aa[i]%k!=0)
{flg=0;break;}

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
int _,n,k;
char a[1000005],b[1000005];
int aa[26];
int main(){
for(scanf("%d",&_);_;--_) {
scanf("%d%d",&n,&k);
scanf("%s%s",a+1,b+1);
memset(aa,0,sizeof(aa));
rep(i,1,n) aa[a[i]-'a']++;
rep(i,1,n) aa[b[i]-'a']--;
int now=0;bool flg=1;
per(i,25,0) {
now-=aa[i];
if(now<0||aa[i]%k!=0)
{flg=0;break;}
}
if(flg) //=1
puts("Yes");
else puts("No");
}
}

|
3月前
|

C++ STL标准库 《string原理与实战分析》
C++ STL标准库 《string原理与实战分析》
60 0
|
4月前
|

Java中循环创建String对象的内存管理分析
Java中循环创建String对象的内存管理分析
59 2
|
3月前
|

Java基础4-一文搞懂String常见面试题，从基础到实战，更有原理分析和源码解析！（二）
Java基础4-一文搞懂String常见面试题，从基础到实战，更有原理分析和源码解析！（二）
37 0
|
3月前
|
JSON 安全 Java
Java基础4-一文搞懂String常见面试题，从基础到实战，更有原理分析和源码解析！（一）
Java基础4-一文搞懂String常见面试题，从基础到实战，更有原理分析和源码解析！（一）
54 0
|

【Java原理探索】带你攻克String类创建的难点分析 | Java开发实战
【Java原理探索】带你攻克String类创建的难点分析 | Java开发实战
121 0
|

「终!」 ☕【Java原理探索】带你进入String类的易错点和底层本质分析！
「终!」 ☕【Java原理探索】带你进入String类的易错点和底层本质分析！
93 0
|

Alexander Stepanov、Meng Lee 在惠普实验室完成的原始版本，本着开源精神，他们声明允许任何人任意运用、拷贝、修改、传播、商业使用这些代码，无需付费。唯一的条件就是也需要向原始版本一样做开源使用。 HP 版本--所有STL实现版本的始祖。
346 0
|

java中的String、StringBuffer和StringBuilder的详细分析

108 0
|

C/CPP中int和string的互相转换详解与多解例题分析
C标准库atoi, atof, atol, atoll(C++11标准) 函数，以及sprintf、sscanf函数，用sstream类，实现C++中int和string的互相转换
210 0