D. Equivalent Strings

Time Limit: 2 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

input
aabb
abab
output
NO

HINT

题意

判断俩字符串是否类似就是说一半的一半是否相同,交换的情况下又是否相同

题解:

暴力

代码

 #include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <vector>
#include <string.h>
using namespace std; typedef __int64 ll;
const int INF = (int)1E9+;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} //*******************************
bool isEqual(char* a,char* b,int len)
{
bool flag=true;
for(int i=;i<len&&flag;i++)
{
if(a[i]!=b[i]) flag=false;
}
if(flag) return true;
if(len&) return false;
return (isEqual(a,b,len/)&&isEqual(a+len/,b+len/,len/))||(isEqual(a+len/,b,len/)&&isEqual(a,b+len/,len/));
} int main()
{
char a[];
char b[];
scanf("%s%s",a,b);
int len=strlen(a);
if(len%)
{
if(strcmp(a,b)==)
{
printf("YES\n");
}
else printf("NO\n");
return ;
}
if(isEqual(a,b,len))
{
printf("YES\n");
}
else printf("NO\n"); return ;
}

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

  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. 1) B. Equivalent Strings DFS暴力

    B. Equivalent Strings Time Limit: 20 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 #313 (Div. 2)(A,B,C,D)

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

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

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

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

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

  8. 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题,其实也很简单,题目保证了小三角形是正 ...

  9. Codeforces Round #302 (Div. 1) C. Remembering Strings DP

    C. Remembering Strings Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

随机推荐

  1. Gradle用户指南(3)-构建Java项目

    1.构建基本的Java项目 为了使用 Java 插件,添加下面代码到构建文件: build.gradle apply plugin: 'java' 这个就是 定义一个 Java 项目的全部.它会将 J ...

  2. 繁华模拟赛 Evensgn的债务

    #include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...

  3. 图论&数据结构——并查集

    Wikioi 4246 NOIP模拟赛Day2T1 奶牛的身高  题目描述 Description 奶牛们在FJ的养育下茁壮成长.这天,FJ给了奶牛Bessie一个任务,去看看每个奶牛场中若干只奶牛的 ...

  4. 草根玩微博 中产玩微信 土豪玩什么?支持Yo的iWatch?

    <中国新媒体发展报告(2014)>发布了一些新媒体的使用情况数据,25.6%无收入群体人数在玩微博,32.0%的微信用户属于月收入3000~5000元的中产阶层,那么土豪会玩什么新媒体呢? ...

  5. 如何看K线图基础知识

    在日K线图中一般白线.黄线.紫线.绿线依次分别表示:5.10.20.60日移动平均线,但这并不是固定的,会根据设置的不同而不同,比如你也可以在系统里把它们设为5.15.30.60均线. 你看K线图的上 ...

  6. Java笔记--泛型总结与详解

    泛型简介: 在泛型没有出来之前,编写存储对象的数据结构是很不方便的.如果要针对每类型的对象写一个数据结构,     则当需要将其应用到其他对象上时,还需要重写这个数据结构.如果使用了Object类型, ...

  7. Centos优化Hadoop

    导读 Hadoop是一个能够让用户轻松架构和使用的分布式计算平台,用户可以轻松地在Hadoop上开发和运行处理海量数据的应用程序,本节讲安装并且优化centos 6.7 系统下的Supper Hado ...

  8. ios5之后arc的问题

    原创: 自从ios5以后, apple官方引进了ARC (automaically reference count 自动索引计数) 这个新特性, 简单的说就是对象设置为nil(空引用)之后, 当自动索 ...

  9. Sum Root to Leaf Numbers

    int sumNumbers(TreeNode *root) { ); } int dfs(TreeNode *root, int sum) { ; if (root->left == null ...

  10. Linux Apache和Nginx网络模型详解

    进程阻塞和挂起的定义: 阻塞是由于进程所需资源得不到满足,并会最终导致进程被挂起     进程挂起的原因并不一定是由于阻塞,也有可能是时间片得不到满足,挂起状态是进程从内存调度到外存中的一种状态,若在 ...