The main idea: to determine whether two strings are equivalent.
Equivalent conditions (any one can be satisfied): 1, two strings exactly the same
2, each string into two parts of the same length, if A1 equivalent to B1 and A2 equivalent to B2, or A1 equivalent to B2 and A2 equivalent to B1
Because the equivalence condition is very vague, I have been stuck for a long time. The 2nd rule in the equivalence condition means that if the 22 substrings of the AB two string satisfy both conditions, then AB is equivalent (a bit around, right), and if we have all read the sentence clearly, then obviously we can recursively judge the equivalence.
First, if the length of the two strings is unequal, then it is certainly not equivalent, and if the length of the current string is odd, then we can determine whether the two strings are strictly equivalent. If the current two strings are already strictly equal, there is no need for recursive judgment.
#include <cstdio> #include <cstring> #define MAXN 200005using namespace Std;char a[maxn],b[maxn];int len; BOOL Check (char *s1,char *s2,int len) {int i;if (len%2 = = 1) {for (i = 0; i < len; i++) if (s1[i]! = S2[i]) return False;retur n true;} else//recursive judgment {return (check (S1,S2,LEN/2) &&check (S1+LEN/2,S2+LEN/2,LEN/2)) | | (Check (S1,S2+LEN/2,LEN/2) &&check (S1+LEN/2,S2,LEN/2));}} int main () {scanf ("%s%s", A, b), int len1 = strlen (a), int len2 = strlen (b), if (len1! = len2) {printf ("no\n"); return 0;} if (check (A,B,LEN1)) printf ("yes\n"), Else printf ("no\n");}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Codeforces Round #313 (Div. 2) equivalent Strings (search)