标签:
Portal: http://codeforces.com/problemset/problem/559/B
年轻时第一次cf的D题,当时直接写了个递归结果爆炸
做法大概是递归时候按字典序乱搞一下
然后就nlogn水过了
1 #include<iostream> 2 #include<algorithm> 3 #include<set> 4 #include<cstdio> 5 #include<cstdlib> 6 #include<cmath> 7 #include<cstring> 8 using namespace std; 9 #define FOR(i,j,k) for(int i=j;i<=k;i++) 10 #define FORD(i,j,k) for(int i=j;i>=k;i--) 11 #define LL long long 12 #define SZ(x) int(x.size()) 13 string a,b; 14 string cg(string s) 15 { 16 if(SZ(s)%2==1) return s; 17 string aa=s.substr(0,(SZ(s))/2); 18 string bb=s.substr((SZ(s))/2,(SZ(s))/2); 19 aa=cg(aa); 20 bb=cg(bb); 21 if(aa<bb) return aa+bb; else return bb+aa; 22 } 23 int main() 24 { 25 cin>>a>>b; 26 a=cg(a); 27 b=cg(b); 28 if(a==b) cout<<"YES"; else cout<<"NO"; 29 return 0; 30 }
P.S 听说有人直接暴力过了这题 %%%
CodeForces 559B Equivalent Strings
标签:
原文地址:http://www.cnblogs.com/mukoiaoi/p/5841936.html