题意:给定一个两个字符串,交换s1的前缀和s2后缀,要求能否通过这样的操作,使得两个字符串相等。
思路:我们来试试样例,交换前缀和后缀,可以观察到,每一个在s1中的字符都是与s2中“相反位置”的字符相对应的,交换时总是它们两个字符之间交换位置,那么这一对字符,是否可以移动到任意位置呢,答案是可以的,通过交换恰好包含当前对字符串,以及目标位置的前后缀,再交换不包含当前对字符的前后缀,实现对当前字符对的位置转移
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<bitset>
#include<cmath>
#include<array>
#include<atomic>
#include<sstream>
#include<stack>
#include<iomanip>
//#include<bits/stdc++.h>
//#define int ll
#define IOS std::ios::sync_with_stdio(false);std::cin.tie(0);
#define pb push_back
#define endl '\n'
#define x first
#define y second
#define Endl endl
#define pre(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,b,a) for(int i=b;i>=a;i--)
#define si(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define ss(x) scanf("%s", x);
#define YES {puts("YES");return;}
#define NO {puts("NO"); return;}
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
typedef pair<char, int> PCI;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<ll, ll> PLL;
const int N = 200010, M = 2 * N, B = N, MOD = 998244353;
const double eps = 1e-7;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
int n, m, k;
char a[N], b[N];
int cnt[30][30];
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lowbit(ll x) { return x & -x; }
ll qmi(ll a, ll b, ll MOD) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
inline void init() {}
void slove()
{
cin >> n;
cin >> a + 1 >> b + 1;
memset(cnt, 0, sizeof cnt);
bool suc = true;
pre(i,1,n)
{
int p = a[i]-'a', q = b[n-i+1]-'a';
if (p > q)swap(p, q);
cnt[p][q]++;
}
pre(i,0,25)
pre(j, i+1, 25)
{
if (cnt[i][j] & 1)
suc = false;
}
int sum = 0;
pre(i, 0, 25) sum += cnt[i][i] % 2;
if (!suc || sum > n % 2)puts("NO");
else puts("YES");
return;
}
signed main()
{
//IOS;
int _;
si(_);
//_ = 1;
init();
while (_--)
{
slove();
}
return 0;
}