码迷,mamicode.com
首页 > 其他好文 > 详细

D. Equivalent Strings

时间:2015-07-23 23:12:21      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

                    D. Equivalent Strings

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <string>
 7 #include <vector>
 8 #include <set>
 9 #include <map>
10 #include <queue>
11 #include <sstream>
12 using namespace std;
13 typedef __int64 LL;
14 const int INF = 0x4ffffff;
15 const double EXP = 1E-5;
16 const LL mod = 1e9+7;
17 const int MS= 200005;
18 
19 
20 bool equals(string s1,string s2)
21 {
22       int len1 = s1.size();
23       int len2 = s2.size();
24       if(s1 == s2)
25             return true;
26      else if(len1 != len2 || (len1&1) ==1 || (len2 &1) ==1)
27            return false;
28       else
29       {
30        //     if(equals(s1.substr(0,len1/2),s2.substr(0,len1/2)) && equals(s1.substr(len1/2,len1/2),s2.substr(len1/2,len1/2)))
31         //          return true;       //  不把这个放后面会超时,因为前面的s1 == s2没有通过。说明相同位置上有字符不同。先交叉比较能够优化。
32 
33              if(equals(s1.substr(0,len1/2),s2.substr(len1/2,len1/2)) && equals(s1.substr(len1/2,len1/2),s2.substr(0,len1/2)))
34                   return true;
35             if(equals(s1.substr(0,len1/2),s2.substr(0,len1/2)) && equals(s1.substr(len1/2,len1/2),s2.substr(len1/2,len1/2)))
36                  return true;
37 
38              return false;
39       }
40 }
41 
42 
43 int main()
44 {
45       string s1,s2;
46       cin>>s1>>s2;
47       if(equals(s1,s2))
48             printf("YES\n");
49       else
50             printf("NO\n");
51       return 0;
52 }

 

D. Equivalent Strings

标签:

原文地址:http://www.cnblogs.com/hutaishi/p/4671817.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!