CodeForces - 560D Equivalent Strings
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:
- 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!
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.
Examples
aaba
abaa
YES
aabb
abab
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".
OJ-ID:
CodeForce-560D
author:
Caution_X
date of submission:
20191026
tags:
dfs
description modelling:
判断两个字符串是否“相等”。
相等:
(1)a=b
(2)a分成长度相等的两份a1,a2,b分成长度相等的两份b1,b2,并满足a1=b1&&a2=b2或者a1=b2&&a2=b1(语法上满足(string)a=(string)a1+(string)a2)。
major steps to solve it:
(1)裸dfs无剪枝
AC code:
#include<bits/stdc++.h>
using namespace std;
bool dfs(string a,string b)
{
int lena=a.length(),lenb=b.length();
string ta1=a.substr(,lena/),ta2=a.substr(lena/,lena/);
string tb1=b.substr(,lenb/),tb2=b.substr(lenb/,lenb/);
if(a==b) return true;
if(a.length()%!=) return false;
if(dfs(ta1,tb2)&&dfs(ta2,tb1)) return true;
if(dfs(ta1,tb1)&&dfs(ta2,tb2)) return true;
return false;
}
int main()
{
string a,b;
cin>>a>>b;
if(a==b) puts("YES");
else if(a.length()!=b.length()) puts("NO");
else if(dfs(a,b)) puts("YES");
else puts("NO");
return ;
}
CodeForces - 560D Equivalent Strings的更多相关文章
- 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 559B - Equivalent Strings
559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...
- Codeforces - 559B - Equivalent Strings - 分治
http://codeforces.com/problemset/problem/559/B 这个题目,分治就好了,每次偶数层可以多一种判断方式,判断它的时间就是logn的(吧),注意奇数层并不是直接 ...
- codeforces 559b//Equivalent Strings// Codeforces Round #313(Div. 1)
题意:定义了字符串的相等,问两串是否相等. 卡了时间,空间,不能新建字符串,否则会卡. #pragma comment(linker,"/STACK:1024000000,102400000 ...
- Codeforces 559B Equivalent Strings 等价串
题意:给定两个等长串a,b.推断是否等价.等价的含义为:若长度为奇数,则必须是同样串.若长度是偶数,则将两串都均分成长度为原串一半的两个子串al,ar和bl,br,当中al和bl等价且ar和br等价, ...
- 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 ...
- Codeforces Round #313 D. Equivalent Strings(DFS)
D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
随机推荐
- Linux 安装指定版本Git
git二进制文件下载地址: https://mirrors.edge.kernel.org/pub/software/scm/git/ 1.下载v2.21.0版本 wget https://mirro ...
- Percona XtraDB Cluster简易入门 - 安装篇
说明 Percona XtraDB Cluster(简称PXC),是由percona公司推出的mysql集群解决方案.特点是每个节点都能进行读写,且都保存全量的数据.也就是说在任何一个节点进行写入操作 ...
- 为什么 WPF 的 Main 方法需要标记 STAThread 。
在编写 WPF 程序时,会发现 Main 方法上方会标记 [STAThread] . 作用:STAThread 标记主线程,也就是 UI 线程是 STA 线程模型. 1 什么是 STA ? 与 STA ...
- JS实现根据两点位置的经纬度获取距离
// 经纬度转换成三角函数中度分表形式. function rad(d) { return d * Math.PI / 180.0; } // 根据经纬度计算距离,参数分别为第一点的纬度,经度:第二点 ...
- 压测应用服务对RabbitMQ消息的消费能力--实践脚本
最近运维跟我反馈我负责的应用服务线上监控到消费RabbitMQ消息队列过慢,目前只有20左右,监控平台会有消息积压的告警. 开发修改了一版应用服务的版本,提交给我做压测验证. 之前没有做过消息中间件的 ...
- Android 布局测试
wrap_content <Button android:id="@+id/button1" android:layout_width="wrap_content& ...
- INSTALL_FAILED_TEST_ONLY
查看博客:http://www.enjoytoday.cn/posts/159 Android studio安装apk无法安装,报错误,网上搜索可以看到都说是:* 调用者不被允许测试的测试程序*,但具 ...
- 测试文档(final)
1 引言 1.1编写目的 编写本测试计划的目的是: (1) 为整个测试阶段的管理工作和技术工作提供指南同时确定测试的内容和范围,为评价系统提供依据: (2) 此外还帮助安排测试活动,说 ...
- Saltstack_使用指南08_远程执行-返回程序
1. 主机规划 salt 版本 [root@salt100 ~]# salt --version salt (Oxygen) [root@salt100 ~]# salt-minion --versi ...
- Centos系统配置bond0
版权声明:本文为博主原创文章,支持原创,转载请附上原文出处链接和本声明. 本文链接地址:https://www.cnblogs.com/wannengachao/p/11942254.html 1.查 ...