You are given two strings ss and tt both of length nn and both consisting of lowercase Latin letters.

In one move, you can choose any length lenlen from 11 to nn and perform the following operation:

  • Choose any contiguous substring of the string ss of length lenlen and reverse it;
  • at the same time choose any contiguous substring of the string tt of length lenlen and reverse it as well.

Note that during one move you reverse exactly one substring of the string ss and exactly one substring of the string tt.

Also note that borders of substrings you reverse in ss and in tt can be different, the only restriction is that you reverse the substrings of equal length. For example, if len=3len=3 and n=5n=5, you can reverse s[1…3]s[1…3] and t[3…5]t[3…5], s[2…4]s[2…4] and t[2…4]t[2…4], but not s[1…3]s[1…3] and t[1…2]t[1…2].

Your task is to say if it is possible to make strings ss and tt equal after some (possibly, empty) sequence of moves.

You have to answer qq independent test cases.

Input

The first line of the input contains one integer qq (1≤q≤1041≤q≤104) — the number of test cases. Then qq test cases follow.

The first line of the test case contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the length of ss and tt.

The second line of the test case contains one string ss consisting of nn lowercase Latin letters.

The third line of the test case contains one string tt consisting of nn lowercase Latin letters.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105 (∑n≤2⋅105∑n≤2⋅105).

Output

For each test case, print the answer on it — "YES" (without quotes) if it is possible to make strings ss and tt equal after some (possibly, empty) sequence of moves and "NO" otherwise.

Example
input

Copy
  1. 4
  2. 4
  3. abcd
  4. abdc
  5. 5
  6. ababa
  7. baaba
  8. 4
  9. asdf
  10. asdg
  11. 4
  12. abcd
  13. badc
output

Copy
  1. NO
  2. YES
  3. NO
  4. YES

大概意思

现在给你两个字符串,你可以进行若干次操作。

每次操作需要在每个字符串都选择出长度为len的一个区间,两个区间位置不一定相同,然后将这个区间的字符都进行翻转。

问你进行若干次操作后,这俩字符串能变成一样的吗?

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n;
  4. string s1,s2,S1,S2;
  5. //前两个满足, 如果两个字符串的逆的奇偶性相同,那么一定是YES
  6. //在判断1和2之后,我们得到的一定是一个排列,问题就变成你可以翻转若干次,两个排列能否相同。
  7. //我们考虑我们同时翻转相同长度的,我们排列的逆一定会发生奇偶性的变化,
  8. //那么如果一开始奇偶性就不同,那么不管怎么翻转,都不会相同。
  9. int Count(string s) {
  10. int num=;
  11. for(int i=; i<s.size(); i++) {
  12. for(int j=; j<i; j++) {
  13. if(s[j]>s[i])
  14. num++;
  15. }
  16. }
  17. return num;
  18. }
  19. void solve() {
  20. cin>>n>>S1>>S2;
  21. s1=S1;
  22. s2=S2;
  23. sort(s1.begin(),s1.end());
  24. sort(s2.begin(),s2.end());
  25. for(int i=; i<n; i++) {
  26. if(s1[i]!=s2[i]) { //如果存在不同字符,那么一定不行
  27. puts("NO");
  28. return;
  29. }
  30. }
  31. for(int i=; i<n; i++) {
  32. if(s1[i]==s1[i-]) {//如果存在相同字符
  33. puts("YES");
  34. return;
  35. }
  36. if(s2[i]==s2[i-]) {
  37. puts("YES");
  38. return;
  39. }
  40. }
  41. if(Count(S1)%==Count(S2)%) {
  42. puts("YES");
  43. } else {
  44. puts("NO");
  45. }
  46. return;
  47. }
  48. int main() {
  49. int t;
  50. scanf("%d",&t);
  51. while(t--)solve();
  52. }

Codeforces Round #598 (Div. 3) F. Equalizing Two Strings的更多相关文章

  1. Codeforces Round #598 (Div. 3) F. Equalizing Two Strings 构造

    F. Equalizing Two Strings You are given two strings s and t both of length n and both consisting of ...

  2. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  3. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  4. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  5. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  6. Codeforces Round #598 (Div. 3)- E. Yet Another Division Into Teams - 动态规划

    Codeforces Round #598 (Div. 3)- E. Yet Another Division Into Teams - 动态规划 [Problem Description] 给你\( ...

  7. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  8. Codeforces Round #598 (Div. 3)

    传送门 A. Payment Without Change 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/4 21:19:19 */ #i ...

  9. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

随机推荐

  1. Win10安装3 —— U盘启动工具安装

    本文内容皆为作者原创,如需转载,请注明出处:https://www.cnblogs.com/xuexianqi/p/12364593.html 一:准备一个空U盘 U盘容量推荐至少8个G,先提前备份好 ...

  2. IP地址分类及其相关计算问题

    IP地址分类及其相关计算问题 公网IP和子网IP 公网IP: • A类:1.0.0.0 到 127.255.255.255 主要分配 给大量主机而局域网网络数量较少的大型网络 • B类:128.0.0 ...

  3. Winform form窗体已弹出框的形式出现并回传值

    From2(弹出框)回传数据到From1 Form1(数据接收form): public string Sstr; private void button1_Click(object sender, ...

  4. 转行小白成长路--java基础

    每天都会发一篇,一点一滴,记录在这条路上的足迹.立个flag 2019年3月份至今已近一年,对信息技术有个大概的了解,个人认为对于这门技术更应该从最底层的原理入手,了解计算机演化的历史,从计算机语言到 ...

  5. Docker之设置加速器

    在Docker从仓库下载镜像是非常慢的,所以今天搞一个Docker设置加速器教程. 1. 创建一个Docker的配置文件. sudo vim /etc/docker/daemon.json 2. 编写 ...

  6. 使用PHP链接MySQL

    一.使用PHP查询MySQL数据库: 1.通过PHP来访问MySQL的步骤是: 连接到MySQL 选择操作的数据库 创建查询的字段 执行查询的语句 检索出结果并在网页上显示 断开与MySQL的连接 我 ...

  7. 在GPU上训练数据

    在GPU上训练数据 模型搬到GPU上 数据搬到GPU上 损失函数计算搬到GPU上

  8. Redis5-集群搭建实验

    集群规划: nodeA:192.168.29.22(22-master,23-slave) nodeB:192.168.29.23(23-master,24-slave) nodeC:192.168. ...

  9. Spring boot --- 自动配置

    spring boot 自动配置 指的是针对很多spring 应用程序常见的应用功能,spring boot 能自动提供相关配置. spring boot 自动配置加载     Spring boot ...

  10. Js 事件委托 解决动态元素不能click点击的问题

    参考教程地址 https://blog.csdn.net/xiaolong20081/article/details/79792137 不想写了.直接看上面就行 采用事件委托或代理方式绑定 $(doc ...