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. linux创建新用户并给予root权限

    root比windows的系统管理员的能力更大,足以把整个系统的大部分文件删掉,导致系统完全毁坏,不能再次使用.所以,用root进行不当的操作是相当危险的,轻微的可以死机,严重的甚至不能开机.所以,在 ...

  2. 洛谷 P1327 数列排序

    P1327 数列排序 题目描述 给定一个数列{an},这个数列满足ai≠aj(i≠j),现在要求你把这个数列从小到大排序,每次允许你交换其中任意一对数,请问最少需要几次交换? 输入输出格式 输入格式: ...

  3. 洛谷 P1781 宇宙总统

    P1781 宇宙总统 题目背景 宇宙总统竞选 题目描述 地球历公元6036年,全宇宙准备竞选一个最贤能的人当总统,共有n个非凡拔尖的人竞选总统,现在票数已经统计完毕,请你算出谁能够当上总统. 输入输出 ...

  4. 1.html+css页面设计

    转自:http://www.cnblogs.com/ywang/archive/2014/04/16/3668638.html 今天用html+css做一个最简单的页面.效果图如下: 说明:这里的韩文 ...

  5. 1.JPA概要

    转自:https://www.cnblogs.com/holbrook/archive/2012/12/30/2839842.html JPA定义了Java ORM及实体操作API的标准.本文摘录了J ...

  6. loadrunner监控apache服务

    一.apache配置步骤(假设apache服务已安装) 1.使用find / -name httpd.conf命令查找httpd.conf文件 2.使用cd opt/lampp/apache2/con ...

  7. jquery验证篇

    jquery验证:验证不了(包括easy ui 插件引用的js) jquery easy ui 引用的js <span style="color:#000000;">& ...

  8. C++胜者树

    #include <iostream> #define MAX_VALUE 0x7fffffff using namespace std; //在这里我先反思一下.不知道怎么搞的,这个算法 ...

  9. 【BZOJ 4556】字符串

    [链接]h在这里写链接 [题意]     给你一个长度为n(n<=10^5)的字符串以及一个整数m(m<=10^5),代表询问的次数.     每个询问由4个整数a,b,c,d给出    ...

  10. mongodb查询部分满足条件的列

    db.tblorders.createIndex( { orderid : -1 },{background:true, name:"index_orderid"} ); db.o ...