codeforce(559B)

#include <bits/stdc++.h>


#define LOCAL
#define ll  long long
#define lll unsigned long long
#define MAX 1000009
#define eps 1e-8
#define INF 0x7fffffff
#define mod 1000000007


using namespace std;


/*
题意:给定两个字符串,如果满足


If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2, then one of the following is correct:
a1 is equivalent to b1, and a2 is equivalent to b2
a1 is equivalent to b2, and a2 is equivalent to b1


输入YES


当两个字符串,长度为奇数时,只有相等时,才会输出YES


否则输出NO


想法:
      暴力递归生成一个字典序最小的字符串,看两个字符串是否表示的相同
      这里所谓的最小表示与字符串最小表示是不同的!!!


*/
string str1,str2;
string smallest(string s)
{
    if (s.length() % 2 == 1) return s;
    string s1 = smallest(s.substr(0, s.length()/2));
    string s2 = smallest(s.substr(s.length()/2,s.length()));
    if (s1 < s2) return s1 + s2;
    else return s2 + s1;
}


int main()
{
    cin>>str1>>str2;
    if(smallest(str1)==smallest(str2))
    {
        puts("YES");
    }
    else
    {
        puts("NO");
    }
    return 0;
}

你可能感兴趣的:(codeforce(559B))