Equivalent Strings

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

题意:

给出两个字符串,确定是否相等。一个字符串分割成相同大小的两半a1和a2,另一个字符串分割成相同大小的成两半b1和b2。

以下是正确的:
a1相当于b1 ,a2相当于b2
a1相当于b2 ,a2相当于b1

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

分析:

求出字符串的长度l。

如果为奇数串,只能比较是否每个字符相同,

如果为偶数串,第一个串分成两个相等长度的串为a, a+l/2,

第二个串也分成b, b+l/2,判断a== b && a+l/2 == b+l/2 || a == b+l/1 && a+l/2 == b.


#include<iostream>
#include<cstring>
using namespace std;
const int maxn=200001;
char a[maxn],b[maxn];
int bj(char*a,char*b,int l) //比较两个字符串是否相等
{
for(int i=0;i<l;i++)
{
if(a[i]!=b[i])
return 0;
}
return 1;
}
int Do(char*a,char*b,int l)
{
int f=0;
if(bj(a,b,l)==1)
f=1;
if(l%2==1) // 奇字符串
{
if(f==1)return 1;
else return 0;
}
else{ //偶字符串
if(f==1) return 1;
else
{
l=l/2;
if(Do(a,b,l)&&Do(a+l,b+l,l)||Do(a,b+l,l)&&Do(a+l,b,l)) //判断
return 1;
else return 0; }
}
}
int main()
{
cin>>a>>b;
int x=strlen(a);
if(Do(a,b,x)==1)
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}

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

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

  4. Equivalent Strings (字符串相等?)

    Equivalent Strings   E - 暴力求解.DFS Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I ...

  5. Codeforces 559B - Equivalent Strings

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

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

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

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

  8. 暴力求解——Equivalent Strings

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

  9. 【24.34%】【codeforces 560D】Equivalent Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. C#从Image上读取文本

    今天通过C#来实现一个读取Image上文本的功能. 1. 环境准备: 1). 下载 Microsoft Office SharePoint Designer 2007. 2). 安装请参考KB:htt ...

  2. JDK 1.5 1.6 override区别

    今天在更新时发现有个别项目报错,报错信息 到网上搜索了之后,根据网上描述,修改了一批配置都不行: http://bestchenwu.iteye.com/blog/997420(这个里面的方法二,即为 ...

  3. 协处理器,王明学learn

    协处理器 协处理器用于执行特定的处理任务,如:数学协处理器可以控制数字处理,以减轻处理器的负担.ARM可支持多达16个协处理器,其中CP15是最重要的一个. CP15提供16组寄存器 通过提供的16组 ...

  4. map[C++]

    //map是一个存储键值对的容器,也是一个双向链表 #include <iostream> using namespace std; #include <map> int ma ...

  5. JavaScript中Eval()函数的作用

    这一周感觉没什么写的,不过在研究dwz源码的时候有一个eval()的方法不是很了解,分享出来一起学习 -->首先来个最简单的理解 eval可以将字符串生成语句执行,和SQL的exec()类似. ...

  6. flex容器属性(一)

    一,概念 flexible box ,意为"弹性布局",用来为盒状模型提供最大的灵活性. 块级布局更侧重于垂直方向,行内布局更侧重于水平方向,于此相对的,弹性盒子布局算法是方向无关 ...

  7. mysql 怎样清空一个数据库中的所有表

    转自:http://blog.csdn.net/zhangzhizhen1988/article/details/8432146 MySQL清空表是很重要的操作,也是最常见的操作之一,下面就为您详细介 ...

  8. 解决mysql shell执行中文表名报command not found错误

    mysql -h 192.168.22.201 -uusername -ppassword --default-character-set=utf8 rom3 -e "DELETE FROM ...

  9. vim 标准环境的配置

    最近刚刚从IDE转到了vim,很多习惯不一致,特地配置了一下vim环境.在网上找了大神的帖子,怕忘记了,特此纪念. 传送门     http://www.cnblogs.com/ma6174/arch ...

  10. J2EE中使用jstl报http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar错

    一.发现问题 运行引用了jstl的jsp页面 报http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or th ...