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/problem/B
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
Sample Output
YES
HINT
题意
判断俩字符串是否相似,相似的条件如下:
a1+a2=A,a1和a2都是A的一半
b1+b2=B,同理
如果A,B相等,那么相似
如果A的长度为偶数{
如果a1与b1,a2与b2相似或者a1与b2,b1与a2相似
那么A,B相似
}
否则不相似
题解:
就如同题目讲的一样,傻逼暴力DFS就好了
不要想多了
代码
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=;
char A[MAXN],B[MAXN];
bool cmp(char x[],char y[],int len)
{
//printf("%d %d\n",x-A,y-B);
bool isok=;
for(int i=;i<len;i++)
if(x[i]!=y[i])isok=;
return isok;
}
bool equ(char x[],char y[],int len)
{
//printf("%d %d %d\n",x-A,y-B,len);
if(cmp(x,y,len))return ;
if(len%==)
return (equ(x,y+len/,len/)&&equ(x+len/,y,len/))
||(equ(x,y,len/)&&equ(x+len/,y+len/,len/));
return ;
}
int main()
{
scanf("%s%s",A,B);
int len=strlen(A);
printf("%s\n",equ(A,B,len) ? "YES" : "NO");
return ;
}
Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力的更多相关文章
- 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. 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. 2) D.Equivalent Strings (字符串)
		
感觉题意不太好懂 = =# 给两个字符串 问是否等价等价的定义(满足其中一个条件):1.两个字符串相等 2.字符串均分成两个子串,子串分别等价 因为超时加了ok函数剪枝,93ms过的. #includ ...
 - Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索
		
Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
 - Codeforces Round #313 (Div. 2)(A,B,C,D)
		
A题: 题目地址:Currency System in Geraldion 题意:给出n中货币的面值(每种货币有无数张),要求不能表示出的货币的最小值.若全部面值的都能表示,输出-1. 思路:水题,就 ...
 - Codeforces Round #313 (Div. 2) 解题报告
		
A. Currency System in Geraldion: 题意:有n中不同面额的纸币,问用这些纸币所不能加和到的值的最小值. 思路:显然假设这些纸币的最小钱为1的话,它就能够组成随意面额. 假 ...
 - codeforces 559b//Equivalent Strings// Codeforces Round #313(Div. 1)
		
题意:定义了字符串的相等,问两串是否相等. 卡了时间,空间,不能新建字符串,否则会卡. #pragma comment(linker,"/STACK:1024000000,102400000 ...
 - Codeforces Round #313 (Div. 2)  A.B,C,D,E  Currency System in Geraldion   	 Gerald is into Art   Gerald's Hexagon   Equivalent Strings
		
A题,超级大水题,根据有没有1输出-1和1就行了.我沙茶,把%d写成了%n. B题,也水,两个矩形的长和宽分别加一下,剩下的两个取大的那个,看看是否框得下. C题,其实也很简单,题目保证了小三角形是正 ...
 
随机推荐
- C++模板知识小结
			
模板定义:模板就是实现代码重用机制的一种工具,它可以实现类型参数化,即把类型定义为参数, 从而实现了真正的代码可重用性.模版可以分为两类,一个是函数模版,另外一个是类模版. 由于类模板包含类型参数,因 ...
 - 【LeetCode 238】Product of Array Except Self
			
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...
 - php 采集程序 宋正河
			
本程序主要是通过php采集网页信息,程序自动存储采集进度,采用phpquery简化元素节点匹配,采集到的内容直接入库 你要做的只是写好采集语法,本程序适合有一定php基础的人使用!当然你也可以进行修改 ...
 - DuiLib消息处理剖析
			
本来想自己写写duilib的消息机制来帮助duilib的新手朋友,不过今天发现已经有人写过了,而且写得很不错,把duilib的主干消息机制都说明了,我就直接转载过来了,原地址:http://blog. ...
 - VS 2013 EFSQLITE
			
在 vs 2013 上用 1.NuGet程序包来获取,它也会自动下载EF6的包 :system.Data.sqlite 他会自动下载 其它几个需要的包. 2.在Sqlite官网上下载对应的版本:htt ...
 - 转——使用Axure制作App原型应该怎样设置尺寸?
			
想用Axure设计一个 APP原型 放到真实的移动设备中演示,但不知道应该使用什么尺寸?若要解释清楚像素和分辨率需要的篇幅比较长,请大家参考百度百科.这里金乌直接给大家提供一个常用的移动设备尺寸列表, ...
 - html5_common.js
			
(function(){ this.sendAjax = function(url,func,formData,type){ type = type || "POST"; //默认 ...
 - Spark on Yarn遇到的几个问题
			
1 概述 Spark的on Yarn模式,其资源分配是交给Yarn的ResourceManager来进行管理的,但是目前的Spark版本,Application日志的查看,只能通过Yarn的yarn ...
 - gradle gradlew 的使用
			
jcenter() 仓库比 mavenCentral() 仓库快,因此最好将jcenter 放前面,这样下载速度最快. 使用本地软件仓库:repositories { flatDir { dirs ' ...
 - SharePoint咨询师之路:设计之前的那些事三:体系结构
			
提示:本系列只是一个学习笔记系列,大部分内容都可以从微软官方网站找到,本人只是按照自己的学习路径来学习和呈现这些知识.有些内容是自己的经验和积累,如果有不当之处,请指正. 咨询师更多的时候是解决方案提 ...