【24.34%】【codeforces 560D】Equivalent Strings
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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:
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.
Examples
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”.
【题目链接】:http://codeforces.com/contest/560/problem/D
【题解】
写个递归就过了;
中间如果遇到字符串的长度为奇数则直接返回false;
感觉这样能剪掉挺多情况的。就交了一发;结果真的过了;
事后看到好多人都在第91个点T了。我看了一下500ms左右。不知道为什么;
还是应该对自己自信点吧!
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
//const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
string s1,s2;
bool f(string a,string b)
{
if (a==b) return true;
int len1 = a.size(),len2 = b.size();
if (len1&1 || len2 &1) return false;
if (len1==1)
return false;
string ta1 = a.substr(0,len1/2),ta2 = a.substr(len1/2,len1/2);
string tb1 = b.substr(0,len2/2),tb2 = b.substr(len2/2,len2/2);
return (f(ta1,tb2)&&f(ta2,tb1))||(f(ta1,tb1)&&f(ta2,tb2));
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> s1;cin >> s2;
if (f(s1,s2))
puts("YES");
else
puts("NO");
return 0;
}
【24.34%】【codeforces 560D】Equivalent Strings的更多相关文章
- 【 BowWow and the Timetable CodeForces - 1204A 】【思维】
题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...
- 【34.57%】【codeforces 557D】Vitaly and Cycle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【24.17%】【codeforces 721D】Maxim and Array
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【24.67%】【codeforces 551C】 GukiZ hates Boxes
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【34.88%】【codeforces 569C】Primes or Palindromes?
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【22.73%】【codeforces 606D】Lazy Student
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)
题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...
- 【codeforces 793D】Presents in Bankopolis
[题目链接]:http://codeforces.com/contest/793/problem/D [题意] 给你n个点, 这n个点 从左到右1..n依序排; 然后给你m条有向边; 然后让你从中选出 ...
- 【codeforces 799D】Field expansion
[题目链接]:http://codeforces.com/contest/799/problem/D [题意] 给你长方形的两条边h,w; 你每次可以从n个数字中选出一个数字x; 然后把h或w乘上x; ...
随机推荐
- worktools-git 工具的使用总结(2)
1.创建分支 git branch son parent //创建分支,是在master 分支的基础上创建 :~/myGit$ git st # On branch master nothing to ...
- Android学习笔记进阶20之得到图片的缩略图
<1>简介 之前往往是通过Bitmap.Drawable和Canvas配合完成,需要写一系列繁杂的逻辑去缩小原有图片,从而得到缩略图. 现在我给大家介绍一种比较简单的方法:(网上有) 在A ...
- 如何使用Linux套接字?
我们知道许多应用程序,例如E-mail.Web和即时通信都依靠网络才能实现.这些应用程序中的每一个都依赖一种特定的网络协议,但每个协议都使用相同的常规网络传输方法.许多人都没有意识到网络协 ...
- 不用浏览器,直接用代码发送文件给webservices所在服务器 并且可以周期行的发送
package com.toic.test; import java.io.DataInputStream; import java.io.DataOutputStream; import java. ...
- vue打包添加样式兼容前缀
在ios8 版本上的h5对flex的支持不太好,需要有兼容的写法. vue-cli自带了postCss autoprefixer 进行兼容处理,配置如下 在vue-loader.config.js中开 ...
- vue中类名和组件经过刷新不对应的解决办法
方法一: 页面路由如下: index.js路由文件如下: { path: '/myOrder', name: '我的订单', menuShow: true, component: myOrder, c ...
- CF741DArpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths(DSU on tree)
题目大意: 给定一个以1为根的树,每条路径上都有一个字符(a~v共22个)询问对于每一个子树内最长的路径上字母经排序后可以形成回文串的最长路径多长 解题思路: 假定给你一个字符串,如何判定其经打乱能否 ...
- 记2018/4/29 qbxt 测试
记 2018/4/29 qbxt 测试(提高基础班) 简单的 NOIP 模拟赛 竞赛时间: 2018 年 4 月 29 日 13:30-17:00 题目名称 乘法 求和 计数 输入文件名 mul.i ...
- [置顶]
WebService学习总结(1)——WebService相关概念
一.序言 大家或多或少都听过 WebService(Web服务),有一段时间很多计算机期刊.书籍和网站都大肆的提及和宣传WebService技术,其中不乏很多吹嘘和做广告的成 分.但是不得不承认的是W ...
- echarts+百度地图+vue 填坑记(一)(百度地图、鼠标移入移出标注,信息框会产生闪烁)
大概七月底开始实习,到现在经历了两个完整的项目(c2b). 因为开发时间紧,任务重,所以在开发过程踩到的坑都没时间去记录. 现在在开发一个某链运输监控系统,到了收尾阶段,有时间写博客了!开心! 一.鼠 ...