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. 基于opencv的手写数字识别(MFC,HOG,SVM)

    参考了秋风细雨的文章:http://blog.csdn.net/candyforever/article/details/8564746 花了点时间编写出了程序,先看看效果吧. 识别效果大概都能正确. ...

  2. 【Linux】Mutex互斥量线程同步的例子

    0.互斥量  Windows下的互斥量 是个内核对象,每次WaitForSingleObject和ReleaseMutex时都会检查当前线程ID和占有互斥量的线程ID是否一致. 当多次Wait**时就 ...

  3. 3 years in Tencent game

    心里一直有继续写博文的愿望,却一直被各种借口打断,现在回头一看,已经在腾讯待了3年半之久.3年半是个比较尴尬的时间点,不好意思说自己是游戏从业老兵,但又觉得自己对于行业已经看到比较清楚了:从当年毕业时 ...

  4. C语言的 (强制类型转换) 以及 '字符字面值'

    C语言的显式/隐式类型转换,都有一个中间变量的存在,原数据的类型.内容都不变. 以下代码,都用GCC编译. #include<stdio.h> int main() { char c = ...

  5. extern "c" 的作用

    作用:实现C和C++混合编程. 原理:C和C++编译器编译之后,函数名会编译成不同的名字,链接阶段名字查找会找不到目标,后面实例中会详解. 用法:①.c文件中定义的函数,.cpp文件要调用时,该.cp ...

  6. Request、Request.Form、Request.QueryString 用法的区别

    Request.Form:获取以POST方式提交的数据. Request.QueryString:获取地址栏参数(以GET方式提交的数据). Request:包含以上两种方式(优先获取GET方式提交的 ...

  7. CreateThread函数&&CString::GetBuffer函数

    对这个两个常见的windows下的函数学习了一下: //最简单的创建多线程实例 #include <stdio.h> #include <windows.h> //子线程函数 ...

  8. Windows Azure 虚拟网络配置(Site to Site)

    上篇我们创建了Point to Site的虚拟网络连接,来满足客户端到云端网络的连接.本篇文章我们将创建Site to Site的虚拟网络连接,以满足本地网络到云端的网络连接. 创建与配置过程与上篇较 ...

  9. 北信源VRVEIS网管软件测试

    650) this.width=650;" border="0" alt="" src="http://img1.51cto.com/att ...

  10. Hadoop应用开发实战案例 第2周

    比如,封面,是一网页,可以看出用户在此网页上,鼠标呈现F形状. 海量Web日志分析 用Hadoop提取KPI统计指标 更详细原文博客:http://blog.fens.me/hadoop-mapred ...