Equivalent Strings
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
aaba
abaa
YES
aabb
abab
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的更多相关文章
- Codeforces Round #313 (Div. 1) B. Equivalent Strings
Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...
- Codeforces Round #313 (Div. 2) D. Equivalent Strings
D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/ ...
- 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 ...
- Equivalent Strings (字符串相等?)
Equivalent Strings E - 暴力求解.DFS Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I ...
- Codeforces 559B - Equivalent Strings
559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...
- Codeforces Round #313 D. Equivalent Strings(DFS)
D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 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 ...
- 暴力求解——Equivalent Strings
Submit Status Description Today on a lecture about strings Gerald learned a new definition of string ...
- 【24.34%】【codeforces 560D】Equivalent Strings
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- PHPCMS 实现上一篇下一篇的几种方法
1第一种 <p>上一篇:{get sql = "select contentid,catid,url,titlee from phpcms_content where conte ...
- 上四条只是我目前总结菜鸟们在学习FPGA时所最容易跑偏的地
长期以来很多新入群的菜鸟们总 是在重复的问一些非常简单但是又让新手困惑不解的问题.作为管理员经常要给这些菜鸟们普及基础知识,但是非常不幸的是很多菜鸟怀着一种浮躁的心态来学习 FPGA,总是急于求成. ...
- iOS经典面试题(转)
iOS经典面试题 前言 写这篇文章的目的是因为前两天同学想应聘iOS开发,从网上找了iOS面试题和答案让我帮忙看看.我扫了一眼,倒吸了一口冷气,仔细一看,气的发抖.整篇题目30多个没有一个答案是对 ...
- ios调用系统导航
#import "ViewController.h" #import <MapKit/MapKit.h> @interface ViewController () @p ...
- 小甲鱼PE详解之IMAGE_DOS_HEADER结构定义即各个属性的作用(PE详解01)
(注:最左边是文件头的偏移量.) IMAGE_DOS_HEADER STRUCT { +0h WORD e_magic // Magic DOS signature MZ(4Dh 5Ah) ...
- DOM兼容
-firstChild firstElementChild var oFirst = oUl.firstChild || oUl.firstElementChild; -lastChild la ...
- 简单用DOM4J结合XPATH解析XML
由于DOM4J在解析XML时只能一层一层解析,所以当XML文件层数过多时使用会很不方便,结合XPATH就可以直接获取到某个元素 使用dom4j支持xpath的操作的几种主要形式 第一种形式 ...
- 改了哪里vs调试直接用iis运行
OAS2Web.csproj 中的useiis为true,但必须要先配置好iis网站指向文件目录
- jQuery.lazyload详解
<SCRIPT src="jquery.js" type=text/javascript></SCRIPT> <SCRIPT src="jq ...
- 使用Gson排除特定字段
http://blog.csdn.net/hknock/article/details/51037564