Equivalent Strings

 
E - 暴力求解、DFS

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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

Input
aaba
abaa
Output
YES
Input
aabb
abab
Output
NO

Hint

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

题意:给两个字符串,判断它们是否相等,相等有两种情况,一个是字符串直接相等,一个是切成长度相同的两份以后两子串相等(两种情况)

题解:直接判断行了,如果当前长度为奇数,如果不是完全相等,直接返回0,否则分两种情况判断

#include<stdio.h>
#include<string.h>
char a[],b[]; int juge(char *p,char *q, int len)
{
if(!strncmp(p,q,len)) //判断怕,p,q字符串长度是否相等
return -;
if(len%)
return ; // 结束判断
int mid=len/;
if(juge(p,q+mid,mid)&&juge(p+mid,q,mid))
return -;
if(juge(p+mid,q+mid,mid)&&juge(p,q,mid))
return -;
} int main()
{
scanf("%s%s",&a,&b);
if(juge(a,b,strlen(a)))
printf("YES");
else
printf("NO");
return ;
}

Equivalent Strings (字符串相等?)的更多相关文章

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

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

  2. Equivalent Strings

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

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

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

  4. 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 ...

  5. Codeforces 559B - Equivalent Strings

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

  6. 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 ...

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

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

  8. Codeforces Round #313 D. Equivalent Strings(DFS)

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

  9. 暴力求解——Equivalent Strings

    Submit Status Description Today on a lecture about strings Gerald learned a new definition of string ...

随机推荐

  1. 《编写高质量代码——Web前端开发修炼之道》读后随笔

    结构样式行为的分离 结构标准包括XML标准.XHTML标准.HTML标准:样式标准有CSS标准:行为标准主要包括DOM标准和ECMAScript标准. 通常的项目会按照如上的方式进行分离,但自己曾今做 ...

  2. KMP算法,Boyer-Moore算法

    http://www-igm.univ-mlv.fr/~lecroq/string/node19.html 首先看普通的串的模式匹配算法开始讲起,才能更深入的了解KMP算法及其优点. 1. 普通的串的 ...

  3. MyEclipse里项目部署到tomcat上之后,tomcat webpps文件夹里为什么找不到这个项目

         今天在MyEclipse中部署了一个java web项目,然后发现报404错误,跑到tomcat目录下的webapps文件夹里并发现没有这个项目,才发现MyEclipse没有写入webapp ...

  4. hdu 3357 水题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3357 #include <cstdio> #include <cmath> # ...

  5. jeecms v7

    http://bbs.jeecms.com/res_base/jeecms_com_bbs/upload/2015_11/jeecmsv7.zip 安装包 http://bbs.jeecms.com/ ...

  6. msyql 字节问题

    MySQL 数据库的varchar类型在4.1以下的版本中的最大长度限制为255,其数据范围可以是0~255或1~255(根据不同版本数据库来定).在 MySQL5.0以上的版本中,varchar数据 ...

  7. J2EE之WebLogic Server

    WebLogic是用于开发.集成.部署和管理大型分布式Web应用. 网络应用和数据库应 用的Java应用server. 将Java的动态功能和Java Enterprise标准的安全性引入大型网络应用 ...

  8. mybatis 与 ehcache 整合[转]

    1.简介 MyBatis 是支持普通SQL 查询,存储过程和高级映射的优秀持久层框架.MyBatis 消除了几乎所有的JDBC 代码和参数的手工设置以及结果集的检索. Ehcache 是现在最流行的纯 ...

  9. Maven Build Life Cycle--reference

    What is Build Lifecycle? A Build Lifecycle is a well defined sequence of phases which define the ord ...

  10. Upgrade to Python 2.7.9 on CentOS5.5

    1. Install python2.7 #cd /tmp #wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz --no-ch ...