Equivalent Strings (字符串相等?)
Equivalent Strings
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
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:
- They are equal.
- 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:
- a1 is equivalent to b1, and a2 is equivalent to b2
- 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
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".
题意:给两个字符串,判断它们是否相等,相等有两种情况,一个是字符串直接相等,一个是切成长度相同的两份以后两子串相等(两种情况)
题解:直接判断行了,如果当前长度为奇数,如果不是完全相等,直接返回0,否则分两种情况判断
#include<stdio.h>
#include<string.h>
char a[],b[]; int juge(char *p,char *q, int len)
{
if(!strncmp(p,q,len)) //判断怕,p,q字符串长度是否相等
return -;
if(len%)
return ; // 结束判断
int mid=len/;
if(juge(p,q+mid,mid)&&juge(p+mid,q,mid))
return -;
if(juge(p+mid,q+mid,mid)&&juge(p,q,mid))
return -;
} int main()
{
scanf("%s%s",&a,&b);
if(juge(a,b,strlen(a)))
printf("YES");
else
printf("NO");
return ;
}
Equivalent Strings (字符串相等?)的更多相关文章
- Codeforces Round #313 (Div. 2) D.Equivalent Strings (字符串)
感觉题意不太好懂 = =# 给两个字符串 问是否等价等价的定义(满足其中一个条件):1.两个字符串相等 2.字符串均分成两个子串,子串分别等价 因为超时加了ok函数剪枝,93ms过的. #includ ...
- Equivalent Strings
Equivalent Strings 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/E 题意: 给出 ...
- 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 ...
- Codeforces 559B - Equivalent Strings
559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...
- 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 ...
- 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 D. Equivalent Strings(DFS)
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 ...
随机推荐
- HTML embed标签使用方法和属性详解
一.基本语法 代码如下: embed src=url 说明:embed可以用来插入各种多媒体,格式可以是 Midi.Wav.AIFF.AU.MP3等等,Netscape及新版的IE 都支持 ...
- 面向GC的Java编程
转自http://hellojava.info/?p=341 HelloJava微信公众账号网站 面向GC的Java编程 Leave a reply 这是内部一个同事(沐剑)写的文章,国外有一家专门做 ...
- 【bzoj2434】[Noi2011]阿狸的打字机
题目描述 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到一台老式的打字机.打字机上只有28个按键,分别印有26个小写英文字母和'B'.'P'两个字母.经阿狸研究发现,这个打字机是这样工作的:l 输入小写字 ...
- Java里的IO流里的FileReader里的BufferedReader读取并在前打印行数!
哈哈!!我又来了!!这个里面没有运用readLine 的方法!!纯手打!! import java.io.BufferedReader; import java.io.FileNotFoundExce ...
- android使用bintray发布aar到jcenter
前言 这两天心血来潮突然想把自己的android library的aar放到jcenter里面,这样一来自己便可以在任何时间任何地点通过internet得到自己的library的引用了,况且现在and ...
- sqlserver 查找某个字符在字符串中第N次出现的位置
例如:查找'A,' 在'A,B,C,D,A,B,C,D,C,D,B,A,C,E,'中第二次出现的位置怎么实现,SQL 中有这样的函数吗? SQL code /* 方法很多,这里简单写一个 返回@fin ...
- Android MVP框架模式
结合前一篇MVC框架模式 为了更好地细分视图(View)与模型(Model)的功能,让View专注于处理数据的可视化以及与用户的交互,同时让Model只关系数据的处理,基于MVC概念的MVP(Mode ...
- Android的Touch系统简介(一
一.Android touch事件的相关概念 用户的Touch事件被包装成MotionEvent 用户当前的touch事件主要类型有: ACTION_DOWN: 表示用户开始触摸. ACTION_MO ...
- Android-Socket传输 GPRS网络
手机使用GPRS网络与server进行Socket通信,代码下载地址:http://download.csdn.net/detail/wu20093346/7768481 用UDP协议与Socket调 ...
- [转] 设计模式 -- Facade
PS:Façade模式注重简化接口,Adapter模式注重转换接口,Bridge模式注重分离接口(抽象)与其实现,Decorator模式注重稳定接口的前提下为对象扩展功能. Facade模式 Faca ...