Codeforces Round #313 (Div. 2) D. Equivalent Strings(简单搜索)

bcftools学习笔记(一) 欢迎关注"生信修炼手册"!本篇主要介绍index, view, query, sort, reheader这五个命令。1. indexindex命令用于对VCF文件建立索... 阅读详情

D. Equivalent Strings
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:

  1. They are equal.
  2. 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:
    1. a1 is equivalent to b1, and a2 is equivalent to b2
    2. 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 test(s)
Input
aaba
abaa
Output
YES
Input
aabb
abab
Output
NO
Note

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".


题目链接:codeforces.com/contest/560/problem/D


题目大意:给出两串长度相等的字符串a,b,问其是否为等价字符串。

                  判断依据为:1.两个字符串相等。

                                        2.把每个字符串拆分成长度相等的两个子串:a=a1+a2,b=b1+b2,如果a1=b2且a2=b1,则a与b等价

深搜递归判断子串是否等价,子串等价,主串就一定等价。注意子串长度相等的条件,不满足不能拆。


代码如下:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
string a,b;
bool eq(int len,string x,string y)//用来判断x,y是否等价
{
	if(x==y)
		return true;
	if(len%2||len==0)       //当主串不能拆时,不等价
		return false;
	len/=2;
	string	a1=x.substr(0,len);
	string	a2=x.substr(len,len);
	string	b1=y.substr(0,len);
	string	b2=y.substr(len,len);
	if(eq(len,a1,b2)&&eq(len,a2,b1))
		return true;
	if(eq(len,a1,b1)&&eq(len,a2,b2))
		return true;
	return false;
}
int main(void)
{
	cin>>a;
	cin>>b;
	bool p=true;
	int len=a.length();
	if(eq(len,a,b))
		printf("YES\n");
	else
		printf("NO\n");
}




细说STM32单片机SPI-Flash芯片的FatFS移植及其应用实例详解 本文以开发板上的SPI-Flash芯片W25Q16为媒介详细介绍CubeMX中FatFS各个参数的意义和设置,分析生成的代码中FatFS各个文件的作用和关联,完成针对W25Q16的硬件访问层的移植。继续使用旺宝红龙开发板STM32F407ZGT6 KITV1.0。 阅读详情

相关推荐

WSL2不能上网,Failed to connect to github.com port 443问题解决方案

WSL2不能上网: 问题:ping外网无效 例如:ping www.baidu.com失败 解决方案: 在wsl: $sudo vi /etc/wsl.conf wsl.conf: [network] generateResolvConf = false 在PowerShell: $sudo vi /etc/etc/resolv.conf resolv.conf: # This file was automatically generated by WSL. To stop automatic gen

Jason_Chen__的博客 9525

Codeforces Round #313 D. Equivalent Strings(DFS)

D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings Gera

叶孤心的专栏 1124

双目相机立体匹配算法概述(含Python代码)

立体匹配任务是计算机视觉中的一个重要问题,旨在从一对具有相同场景的图像中估计每个像素的视差(disparity)。本文对现有的传统算法和深度学习算法进行了综述,以便于各位选择合适的立体匹配算法用于深度估计或三维建模。

m0_59257547的博客 8291

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 standard input output standard output Today on a lecture about strings Gera

GKHack's Blog 1616

解决Windows 10更新失败错误代码0x80070643

在Windows 10操作系统的更新过程中,用户时常会遇到各类错误代码,这些代码通常成为顺利完成更新的绊脚石。其中,错误代码0x80070643是一个较为常见的更新失败提示,它可能导致系统更新停滞不前。面对这一挑战,本文将详细介绍如何有效解决这一错误,帮助用户顺利完成Windows 10的更新。

nntxthml的博客 1826

冰河木马实验(V8.4)

简述: 百科词条 冰河木马开发于1999年,跟灰鸽子类似,在设计之初,开发者的本意是编写一个功能强大的远程控制软件。但一经推出,就依靠其强大的功能成为了黑客们发动入侵的工具,并结束了国外木马一统天下的局面,跟后来的灰鸽子等等成为国产木马的标志和代名词。 冰河的服务器端程序为G-server.exe,客户端程序为G-client.exe,默认连接端口为7626。其中攻击者使用G-client.e...

野原新之助 1万+

Codeforces Round #313 (Div. 2)560D. Equivalent Strings

D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings Gera

KeyboardPianist的博客 925

N5105 PVE UEFI核显直通Windows:从黑屏到HDMI输出的实战调优

本文详细介绍了在N5105处理器上实现PVE UEFI核显直通Windows的实战调优方法。针对黑屏和HDMI音频无法识别等常见问题,提供了系统参数调整、驱动模块加载、虚拟机配置等解决方案,帮助用户成功实现核显直通并优化性能。

weixin_42566424的博客 203

Codeforces Round #313 (Div. 2) D. Equivalent Strings 解题心得

原题: Description Today on a lecture about strings Gerald learned a new definition of string equivalency. Two stringsaandbof equal length are calledequivalentin one of the two cases: ...

advyne9986的博客 152

STM32平台下FreeModbus TCP协议栈集成指南

深入讲解在STM32平台如何移植和配置freemodbus协议栈,实现TCP通信功能。结合嵌入式开发细节,帮助开发者快速掌握freemodbus的应用与调试技巧。

weixin_36001279的博客 1142

计算机视觉教程1-1:透视空间与透视变换

在生活中,透视现象很常见,其物理本质是光的直线传播。由于人眼与相机在捕获图像时均存在透视现象,因此计算机几何基于透视空间进行研究。本节介绍透视变换原理

FRIGIDWINTER的博客 3089

Codeforces Round #313 (Div. 2) D. Equivalent Strings

D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings...

149

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Codeforces Round #313 (Div. 2)——D递归,stirng——Equivalent Strings

Today on a lecture about strings Gerald learned a new definition of string equivalency. Two stringsaandbof equal length are calledequivalentin one of the two cases: They are equal. If ...

dgjm4087的博客 152

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Codeforces Round #313 (Div. 2) D Equivalent Strings

题意 划分字符串 a1 b1 a2 b2 若a1=b2&&a2=b1 || a1=b1&&a2=b2 输出YES 若为偶数则不断划分 到奇数的时候则判断 两个字符串每一位是否相等 不能用strcmp #include #include #include #include using namespace std; const int MAX = 200100; char str1[M

WORK HARD IN SILENCE LET SUCCESS MAKE THE NOISE 461

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Codeforces Round #313 (Div. 2) D. Equivalent Strings 字符串处理

D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings Gera

习惯与规则决定命运 1413

Equivalent Strings(Codeforces Round #313 (Div. 2) D)

此题链接单击这里=================#include <iostream> #include <string> #include <vector> using namespace std; string a,b; bool funt(int fa,int la,int fb,int lb) { int i,j; for(i=fa,j=fb;i<la;i++,j++)

Folieshell的博客 388

Codeforces Round #313 (Div. 2) Problem D - Equivalent Strings

CF 313 DIV2 D

Accepted丶 486

Codeforces Round #313 (Div. 2)D. Equivalent Strings(字符串)

D. Equivalent StringsToday on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:They are e

龙崎的专栏 561

Codeforces Round #313 (Div. 2) D. Equivalent Strings

D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/problem/B Description Today on a lecture about strings Gerald learned a new definiti...

weixin_30610755的博客 75

Codeforces Round #313 (Div. 2) D Equivalent Strings(dfs)

这道题先用了笨办法,就是用中间数组复制字符串,再比较,这样不仅浪费时间,而且最后做了半天还wa了,爆栈了Orz。想一个好的方法确实是事半功倍啊~~

hi_just_do_it的博客 255

Codeforces Round #313 Equivalent Strings(递归)

D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Today on a lecture about strings Gera

把复杂的事情简单描述 476

Codeforces Round #313 (Div. 2) D. Equivalent Strings(字符串+递归)

题意: 给两个字符串,判断是否"相等"。 这里”相等“的定义是:1、字符串对应字符相同; 2、将第一个字符串对半分成c1和d1,第二个字符串对半分成c2和d2。 如果c1==c2 && d1==d2 或者c1==d2 && c2==d1则两个字符串相等。 当字符串长度为奇数时,只有两个字符串对应字符相同才相等。 分析: 结合题意和样例,可以看出这...

weixin_34071713的博客 103
上一篇: Codeforces Round #313 (Div. 2) C. Gerald's Hexagon(补大三角形)
下一篇: A Math game (DFS+剪枝)
雨狮子
博客等级 码龄12年 24粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值