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 ...
随机推荐
- myeclipse报错: java compiler level does not match the version of the installed java project facet
在升级到myeclipse 9.0正式版后,很无耐地出发现了一个error级别的错误,虽然没在代码中,但是看着让人很不舒服.第一反应就是到网上搜索解决之道,结果,网站说在工程的属性中去找个叫啥&quo ...
- php获取当前毫秒时间戳
最近在做一个智能家居项目的后台,需要实时上传用户对智能设备的配置信息到服务器,以便实现同步,因此对于时间的精确度要求比较高,最开始直接是用php的time()函数来获取时间戳,获取的时间精确到秒级别, ...
- Effective C++ 之 0 导读(Introduction)
Effective C++ 导读 (Introduction) 术语(terminology) 声明式 (declaration) 是告诉编译器某个东西的名称和类型(type),但略去细节.以下都是声 ...
- win10无法枚举容器中的对象 访问被拒绝
http://jingyan.baidu.com/article/48a42057cd0bc0a924250419.html
- input实时监控和获取焦点的问题,oninput,ononfocus
1.input监控实时输入问题,google浏览器使用oninput,其他浏览器(IE6/7/8)使用onpropertychange var ie = !!window.ActiveXObject; ...
- 汇编学习(五)——表处理程序
(一)串操作指令及重复前缀 一.串操作指令: 1.串传送指令: (1)指令格式: MOVS dst,rsc MOVSB ;ES:[DI]<--DS:[SI],SI<-SI+/-,DI< ...
- Apache Tomcat配置
- supervisor简介
一什么是supervisor Superviosr是一个UNIX-like系统上的进程监控工具. Supervisor是一个Python开发的client/server系统,可以管理和监控*nix上面 ...
- HDU 5652 India and China Origins(经典并查集)
特别经典的一个题,还有一种方法就是二分+bfs 题意:空间内n*m个点,每个点是0或者1,0代表此点可以走,1代表不能走.接着经过q年,每年一个坐标表示此点不能走.问哪年开始图上不能出现最上边不能到达 ...
- 在C#程序中实现插件架构
阅读提示:这篇文章将讲述如何利用C#奇妙的特性,实现插件架构,用插件(plug-ins)机制建立可扩展的解决方案. 在.NET框架下的C#语言,和其他.NET语言一样提供了很多强大的特性和机制.其中一 ...