题目大意:
就是根据题目中给出的定义判断两个串是否相同
大致思路:
....前来补好久之前没补的题....
当时这个题比赛的时候直接递归根据定义用Hash判断的然后TLE了....
好吧毕竟不是正解
这个题的正确做法是每次将串分成两半按照字典序排序, 这样递归回溯排好之后, 如果两个串根据题目中的定义是相同的话, 那么这样做之后一定会使得两个串相同
并且时间复杂度也是严格意义上的O(nlogn)
代码如下:
Result : Accepted Memory : 400 KB Time : 31 ms
/*
* Author: Gatevin
* Created Time: 2015/8/14 12:20:00
* File Name: Sakura_Chiyo.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;
#define maxn 200010
char s1[maxn], s2[maxn];
void change(char *s, int L, int R)
{
int len = (R - L + 1);
if(len & 1) return;
change(s, L, L + len/2 - 1);
change(s, R - len/2 + 1, R);
bool less = 1;
for(int i = 0; i < len/2; i++)
{
if(s[L + i] < s[L + len/2 + i])
break;
if(s[L + i] > s[L + len/2 + i])
{
less = 0;
break;
}
}
if(!less)
for(int i = 0; i < len/2; i++)
swap(s[L + i], s[L + len/2 + i]);
return;
}
int main()
{
scanf("%s", s1);
scanf("%s", s2);
int len = strlen(s1);
change(s1, 0, len - 1);
change(s2, 0, len - 1);
for(int i = 0; i < len; i++)
if(s1[i] != s2[i])
{
puts("NO");
return 0;
}
puts("YES");
return 0;
}