Codeforces Round #648 (Div. 2) F - Swaps Again 思维
作者:互联网
对应位置的数字之间的关系是不变的,直接利用这一点就可以做
开始还写了ida*,结果t飞了
#include<map> #include<queue> #include<time.h> #include<limits.h> #include<cmath> #include<ostream> #include<iterator> #include<set> #include<stack> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep_1(i,m,n) for(int i=m;i<=n;i++) #define mem(st) memset(st,0,sizeof st) int read() { int res=0,ch,flag=0; if((ch=getchar())=='-') //判断正负 flag=1; else if(ch>='0'&&ch<='9') //得到完整的数 res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res; } typedef long long ll; typedef pair<int,int> pii; typedef unsigned long long ull; typedef pair<double,double> pdd; const int inf = 0x3f3f3f3f; const int N=550; int b[N]; int b1[N]; int a[N]; int a1[N]; map<pii,int>mp; void solve() { int n; cin>>n; mp.clear(); for(int i=1; i<=n; i++) cin>>a[i],a1[i]=a[i]; for(int i=1; i<=n; i++) cin>>b[i],b1[i]=b[i]; sort(a1+1,a1+1+n); sort(b1+1,b1+1+n); for(int i=1; i<=n; i++) if(a1[i]!=b1[i]) { cout<<"No"<<endl; return ; } for(int i=1; i<=(n+1)/2; i++) mp[ {min(a[i],a[n-i+1]),max(a[i],a[n-i+1]) } ] ++; for(int i=1; i<=(n+1)/2; i++) if(mp[ {min(b[i],b[n-i+1]),max(b[i],b[n-i+1]) } ]==0) { cout<<"No"<<endl; return ; } else { mp[ {min(b[i],b[n-i+1]),max(b[i],b[n-i+1]) } ] --; continue; } cout<<"Yes"<<endl; return ; } signed main() { int t; cin>>t; while(t--) solve(); return 0; }
标签:Again,typedef,ch,Swaps,int,Codeforces,a1,b1,include 来源: https://www.cnblogs.com/QingyuYYYYY/p/13110598.html