D. 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".

    #include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h> using namespace std; char a[200010],b[200010]; int DFS(char *a,char *b,int l)
{
if(strncmp(a,b,l) == 0)
{
return 1;
}
if(l%2)
{
return 0;
}
int p = l / 2;
if((DFS(a,b+p,p) && DFS(a+p,b,p)) || (DFS(a,b,p) && DFS(a+p,b+p,p)))
{
return 1;
}
return 0;
} int main()
{
while(scanf("%s",a)!=EOF)
{
scanf("%s",b);
int len = strlen(a);
int pk = DFS(a,b,len);
if(pk == 1)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}

Codeforces Round #313 D. Equivalent Strings(DFS)的更多相关文章

  1. Codeforces Round 662 赛后解题报告(A-E2)

    Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...

  2. Codeforces Round #306 (Div. 2) ABCDE(构造)

    A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...

  3. CodeForces 165C Another Problem on Strings(组合)

    A string is binary, if it consists only of characters "0" and "1". String v is a ...

  4. Codeforces Round #527 (Div. 3)F(DFS,DP)

    #include<bits/stdc++.h>using namespace std;const int N=200005;int n,A[N];long long Mx,tot,S[N] ...

  5. Codeforces Round #267 (Div. 2)D(DFS+单词hash+简单DP)

    D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. 【Codeforces 723D】Lakes in Berland (dfs)

    海洋包围的小岛,岛内的有湖,'.'代表水,'*'代表陆地,给出的n*m的地图里至少有k个湖,求填掉面积尽量少的水,使得湖的数量正好为k. dfs找出所有水联通块,判断一下是否是湖(海水区非湖).将湖按 ...

  7. codeforces 805 E. Ice cream coloring(dfs)

    题目链接:http://codeforces.com/contest/805/problem/E 题意:你有n个节点,这个n个节点构成一棵树.每个节点拥有有si个类型的ice,同一个节点的ice互相连 ...

  8. codeforces 682C Alyona and the Tree(DFS)

    题目链接:http://codeforces.com/problemset/problem/682/C 题意:如果点v在点u的子树上且dist(u,v)>a[v]则u和其整个子树都将被删去,求被 ...

  9. Codeforces Round #309 (Div. 1) A(组合数学)

    题目:http://codeforces.com/contest/553/problem/A 题意:给你k个颜色的球,下面k行代表每个颜色的球有多少个,规定第i种颜色的球的最后一个在第i-1种颜色的球 ...

随机推荐

  1. 第九章 搭建Hadoop 2.2.0版本HDFS的HA配置

    Hadoop中的NameNode好比是人的心脏,非常重要,绝对不可以停止工作.在hadoop1时代,只有一个NameNode.如果该NameNode数据丢失或者不能工作,那么整个集群就不能恢复了.这是 ...

  2. js用new Object创建json数据

    var str = '';var json = new Object;var arr =new Array(); for(var i =0; i<4;i++){        var jsons ...

  3. bash deploy.sh 通过bash命令 执行scp -r 命令将本地文件拷贝到服务器

    deploy.sh 文件内容如下 #!/bin/bash #scp -r ./* root@XXXXX:/root/sunSH/xadserver/ function getdir(){ for el ...

  4. Jar/War/Ear等包的作用与区别详解

    以客户角度来看,jar文件就是一种封装格式,用户不需要知道jar包中有多少个.class格式的文件及每个文件中的功能与作用,也可以得到相应的访问的结果.java中除了jar格式还有war和ear等包文 ...

  5. python学习笔记(18)--eclipse更换主题

    说明: 1. 在eclipse marketplace 搜索color ide pack安装 2. 参考文章和评论http://blog.csdn.net/wusuopubupt/article/de ...

  6. H - Quicksum(1.5.3)

    Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit cid=1006#sta ...

  7. 【Visual Studio】解决方案未保存,请先保存你的解决方案,然后再管理Nuget包

    上网下的Demo,文件夹中没有.sln文件,用VS打开.csproj文件来打开方案.此时可能因为一些引用问题想打开Nuget包管理器,会弹出如下提示: 解决方案未保存,请先保存你的解决方案,然后再管理 ...

  8. 【C#】获取机器码MachineCode

    需求:机器码可以用于校验用户是否用的同一台电脑登录,比如在别的机器上登录时做强制下线(踢人下线).通常在用户注册时,计算一次用户的机器码跟随注册信息一起发送给服务器. 机器码的作用看百度百科: 定义规 ...

  9. 集群负载均衡LVS

    电子商务已经成为生活中不可缺少的一部分,给用户带来了方便和效率.随着计算机硬件的 发展,单台计算机的性能和可靠性越来越高.网络的飞速发展给网络宽带和服务器带来巨大的 挑战,网络宽带的增长速度远远高于内 ...

  10. redis调优

    1.先把持久化数据备份一份,然后使用rdb分析工具分析一下大的键值2.然后DBA删除一部分不用的3.然后再配置最大内存 千万不要没清理数据就直接把内存限制较小 那样会触发redis对内存达到限制的处理 ...