B. Equivalent Strings

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/559/problem/B

Description

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 Input

aaba
abaa

Sample Output

YES

HINT

题意

判断俩字符串是否相似,相似的条件如下:

a1+a2=A,a1和a2都是A的一半

b1+b2=B,同理

如果A,B相等,那么相似

如果A的长度为偶数{

  如果a1与b1,a2与b2相似或者a1与b2,b1与a2相似

  那么A,B相似

}

否则不相似

题解:

就如同题目讲的一样,傻逼暴力DFS就好了

不要想多了

代码

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=;
char A[MAXN],B[MAXN];
bool cmp(char x[],char y[],int len)
{
//printf("%d %d\n",x-A,y-B);
bool isok=;
for(int i=;i<len;i++)
if(x[i]!=y[i])isok=;
return isok;
}
bool equ(char x[],char y[],int len)
{
//printf("%d %d %d\n",x-A,y-B,len);
if(cmp(x,y,len))return ;
if(len%==)
return (equ(x,y+len/,len/)&&equ(x+len/,y,len/))
||(equ(x,y,len/)&&equ(x+len/,y+len/,len/));
return ;
}
int main()
{
scanf("%s%s",A,B);
int len=strlen(A);
printf("%s\n",equ(A,B,len) ? "YES" : "NO");
return ;
}

Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力的更多相关文章

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

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

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

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

  3. Codeforces Round #313 (Div. 2) 560D Equivalent Strings(dos)

    D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. Codeforces Round #313 (Div. 2) D.Equivalent Strings (字符串)

    感觉题意不太好懂 = =# 给两个字符串 问是否等价等价的定义(满足其中一个条件):1.两个字符串相等 2.字符串均分成两个子串,子串分别等价 因为超时加了ok函数剪枝,93ms过的. #includ ...

  5. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  6. Codeforces Round #313 (Div. 2)(A,B,C,D)

    A题: 题目地址:Currency System in Geraldion 题意:给出n中货币的面值(每种货币有无数张),要求不能表示出的货币的最小值.若全部面值的都能表示,输出-1. 思路:水题,就 ...

  7. Codeforces Round #313 (Div. 2) 解题报告

    A. Currency System in Geraldion: 题意:有n中不同面额的纸币,问用这些纸币所不能加和到的值的最小值. 思路:显然假设这些纸币的最小钱为1的话,它就能够组成随意面额. 假 ...

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

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

  9. Codeforces Round #313 (Div. 2) A.B,C,D,E Currency System in Geraldion Gerald is into Art Gerald's Hexagon Equivalent Strings

    A题,超级大水题,根据有没有1输出-1和1就行了.我沙茶,把%d写成了%n. B题,也水,两个矩形的长和宽分别加一下,剩下的两个取大的那个,看看是否框得下. C题,其实也很简单,题目保证了小三角形是正 ...

随机推荐

  1. Delphi 之前解析串口数据

    //串口接收数据procedure TfrmClientMain.Comm1ReceiveData(Sender: TObject; Buffer: Pointer; BufferLength: Wo ...

  2. unittest框架的注意点

    这篇并不是讲unittest如何使用,而是记录下在和htmltestrunner集成使用过程中遇到的一些坑,主要是报告展示部分. 我们都知道python有一个单元测试框架pyunit,也叫unitte ...

  3. linux笔记_20150417_ubuntu 常见问题_文件_音乐播放器

    最近在学习ubuntu的过程中,遇到了一些问题,就记下来了它的解决办法.以希望对你也有用. ),至少保证周围局域网内用户可以访问.至于配置文件,内容比较少,反正对我来讲能用就ok了~不知道会不会很弱 ...

  4. unity3d Human skin real time rendering 真实模拟人皮实时渲染(转)

    先放出结果图片...由于网上下的模型是拼的,所以眼皮,脸颊,嘴唇看起来像 存在裂痕,解决方式是加入曲面细分和置换贴图 进行一定隆起,但是博主试了一下fragment shader的曲面细分,虽然细分成 ...

  5. C# 保留2位小数

    1.只要求保留N位不四舍5入 float   f   =   0.55555f;                 int   i   =(int)(f   *   100);             ...

  6. R command

    setwd("D:/Research/code/rcode")    #notice the "/" list.files(getwd()) heisenber ...

  7. Map/Reduce中Join查询实现

    张表,分别较data.txt和info.txt,字段之间以/t划分. data.txt内容如下: 201001    1003    abc 201002    1005    def 201003  ...

  8. Struts Convention Plugin 流程 (2.1.6+)

    首先添加lib: <dependency> <groupId>org.apache.struts</groupId> <artifactId>strut ...

  9. 笔记:修改centos的IP地址相关配置

    最近碰到不少认识的人问相关问题 索性做个笔记 图个方便 修改eth0的网卡配置vi /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0BOOTPR ...

  10. carthage 简单使用步骤

    brew install carthage切至项目目录:cd xxx创建Cartfile文件vi Cartfile填写依赖git "https://xxxxx" "mas ...