題目
題意:
對於一個字符串,我每次可以選擇一定數量的前綴,然後和相同數量的後綴進行交換,交換的話,是第一位對應着第一位進行交換的,問最後能不能將這些字符交換後,形成兩個序列一致。
思路:
我們在交換的時候可以發現比如如果只交換兩個的話,那麼就是,我們可以發現這三組都是沒有任何變化的,那麼也就是無論怎麼移,每一組都是一樣的,所以我們只要將判斷每一組的元素是否一樣,因爲如果元素一樣,那麼通過不斷選擇前後綴就可以達到一致。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <cctype>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return ;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1:1;
ret = (c == '-') ? 0:(c - '0');
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return ;
}
int xxxxxxxxx = 1;
inline void outi(int x) {if (x > 9) outi(x / 10);putchar(x % 10 + '0');}
inline void outl(ll x) {if (x > 9) outl(x / 10);putchar(x % 10 + '0');}
inline void debug(ll x) {cout << xxxxxxxxx++ << " " << x << endl;}
inline void debugs(string s) {cout << s << endl;}
const int maxn = 510;
int a[maxn], b[maxn];
pii pa[maxn], pb[maxn];
int main() {
int t; read(t); while (t--) {
int n; read(n); for (int i = 1; i <= n; i++) read(a[i]);
for (int i = 1; i <= n; i++) read(b[i]);
if (n % 2 == 1 && a[n / 2 + 1] != b[n / 2 + 1]) {
printf("No\n");
continue;
}
for (int i = 1; i <= n / 2; i++) {
pa[i] = make_pair(min(a[i], a[n - i + 1]), max(a[i], a[n - i + 1]));
pb[i] = make_pair(min(b[i], b[n - i + 1]), max(b[i], b[n - i + 1]));
}
sort(pa + 1, pa + 1 + n / 2);
sort(pb + 1, pb + 1 + n / 2);
bool flag = false;
for (int i = 1; i <= n / 2; i++) {
if (pa[i] != pb[i]) flag = true;
}
if (flag) printf("No\n");
else printf("yes\n");
}
return 0;
}