B. Equivalent Strings
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of
equal length are calledequivalent in one of the two cases:

  1. They are equal.
  2. 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:

    1. a1 is
      equivalent to b1,
      and a2 is
      equivalent to b2
    2. a1 is
      equivalent to b2,
      and a2 is
      equivalent to b1

As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.

Gerald has already completed this home task. Now it's your turn!

Input

The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200 000 and
consists of lowercase English letters. The strings have the same length.

Output

Print "YES" (without the quotes), if these two strings are equivalent, and "NO"
(without the quotes) otherwise.

Sample test(s)
input
aaba
abaa
output
YES
input
aabb
abab
output
NO
Note

In the first sample you should split the first string into strings "aa" and "ba",
the second one — into strings "ab" and "aa". "aa"
is equivalent to "aa"; "ab" is equivalent to "ba"
as "ab" = "a" + "b",
"ba" = "b" + "a".

In the second sample the first string can be splitted into strings "aa" and "bb",
that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".


题目看错了666

能分就分,且把字典序小的排前面

#include<bits/stdc++.h>
using namespace std; string equ(string s)
{
int n=s.length();
if (n&1) return s;
string s1= equ(s.substr(0,n/2));
string s2= equ(s.substr(n/2,n/2));
if (s1<s2) return s1+s2;
return s2+s1;
}
string s1,s2;
int main()
{
cin>>s1>>s2;
if (equ(s1).compare(equ(s2))==0)
{
cout<<"YES"<<endl;
}
else cout<<"NO"<<endl;
return 0;
}

CF 559B(Equivalent Strings-构造法)的更多相关文章

  1. Codeforces 559B - Equivalent Strings

    559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...

  2. Codeforces 559B Equivalent Strings 等价串

    题意:给定两个等长串a,b.推断是否等价.等价的含义为:若长度为奇数,则必须是同样串.若长度是偶数,则将两串都均分成长度为原串一半的两个子串al,ar和bl,br,当中al和bl等价且ar和br等价, ...

  3. codeforces 559b//Equivalent Strings// Codeforces Round #313(Div. 1)

    题意:定义了字符串的相等,问两串是否相等. 卡了时间,空间,不能新建字符串,否则会卡. #pragma comment(linker,"/STACK:1024000000,102400000 ...

  4. Codeforces - 559B - Equivalent Strings - 分治

    http://codeforces.com/problemset/problem/559/B 这个题目,分治就好了,每次偶数层可以多一种判断方式,判断它的时间就是logn的(吧),注意奇数层并不是直接 ...

  5. Codeforces Round #313 (Div. 1) B. Equivalent Strings

    Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...

  6. Equivalent Strings

    Equivalent Strings 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/E 题意: 给出 ...

  7. Codeforces Round #313 (Div. 2) D. Equivalent Strings

    D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/ ...

  8. Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力

    B. Equivalent Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559 ...

  9. Uva 120 - Stacks of Flapjacks(构造法)

    UVA - 120  Stacks of Flapjacks Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld &a ...

随机推荐

  1. 如何优雅的写UI——(1)MFC六大核心机制-程序初始化

    很多做软件开发的人都有一种对事情刨根问底的精神,例如我们一直在用的MFC,很方便,不用学太多原理性的知识就可以做出各种窗口程序,但喜欢钻研的朋友肯定想知道,到底微软帮我们做了些什么,让我们在它的框架下 ...

  2. [Python] Different ways to test multiple flags at once in Python

    x, y, z = 0, 1, 0 if x == 1 or y == 1 or z == 1: print('passed') if 1 in (x, y, z): print('passed') ...

  3. startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag

    startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVI ...

  4. Weblogic问题汇总

    1. weblogic unable to get file lock问题 在项目使用过程中,非正常结束Weblogic进程导致Weblogic无法启动,出现以下错误: <BEA-141281& ...

  5. jquery中prop()和attr()的使用

    jquery1.6+出现的prop()方法. • 对于HTML元素本身就带有的固有属性,在处理时,使用prop方法. • 对于HTML元素我们自己自定义的DOM属性,在处理时,使用attr方法. • ...

  6. 16、cgminer学习之:pthread_mutex_init和pthread_cond_init

    1.原理 假设有两个线程同时访问一个全局变量 n,这个全局变量的初始值等于0. Int  n = 0 ; 消费者线程 A 进入临界区,访问 n,A 必须等到 n 大于 0 才能接着往下执行,如果 n= ...

  7. Javascript和jquery事件--鼠标右键事件,contextmenu

    右键点击触发是浏览器的默认菜单事件contextmenu,你可以选择阻止它,使用event.preventDefault();或者return false;. 想要定义右键点击事件,关注的是mouse ...

  8. Java基础学习总结(31)——Java思维导图

  9. GridView与ArrayAdapter的结合

    activity_main.xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android ...

  10. C语言中 / 得到的结果