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 ...
随机推荐
- hdu 5288 数学 ****
给一个序列 定义函数f(l ,r) 为区间[l ,r] 中 的数ai不是在这个区间其他任意数aj的倍数 求所有f(l,r)之和 通过预处理,记录 a[i] 的左右边界(所谓的左右边界时 在从 a[i] ...
- 配置ogg异构oracle-mysql(2)源端配置
源端配置大致分为如下三个步骤:配置mgr,配置抽取进程,配置投递进程 在源端先创建一张表,记得带主键: SQL> create table ah4(id int ,name varchar(10 ...
- Android系统架构
Linux内核层 为Android的各种设备提供了底层驱动 系统运行库层 为Android提供一些底层的库,如数据库.3D绘图等 应用框架层 核心API 应用层 具体的手机application An ...
- Arduino101学习笔记(三)—— 101简介
一.板子图示--摘自中文社区 二.技术规格 主控器 Intel Curie 工作电压 3.3V (I/O兼容5V) 输入电压 (推荐) 7-12V 输入电压 (极限) 6-20V 数字 I/O 14 ...
- Java生成验证码小工具
无意中看到一个生成简易验证码的小工具类(保存学习): 工具类代码: import java.awt.BasicStroke; import java.awt.Color; import java.aw ...
- 【前台 ajax】web项目前台传递数组给后台 两种方式
项目使用maven springMVC 有需求 将前台的数组 在ajax中 送给后台 方式1: 前台代码:[注意:ajax中的属性---traditional:true, ] 如果Post ...
- 廖雪峰教程笔记:js中map和reduce的用法
举例说明,比如我们有一个函数f(x)=x2,要把这个函数作用在一个数组[1, 2, 3, 4, 5, 6, 7, 8, 9]上,就可以用map实现如下: 由于map()方法定义在JavaScript的 ...
- PHP 汉字转拼音
<?php/** *+------------------------------------------------------ * PHP 汉字转拼音 *+----------------- ...
- 疯狂java笔记(七) - Java集合之Map
Map是以键值对(key-value)的形式来存储数据的.而且Map不允许key的重复,通过Map存储key-value对时,只需要考虑key的存储就可以,key存储后value就会跟着key(完全可 ...
- CodeForces#275--DIV 2--B(BinarySearch)(!!)
B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input stand ...