CF 559B(Equivalent Strings-构造法)
2 seconds
256 megabytes
standard input
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 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
- a1 is
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.
Print "YES" (without the quotes), if these two strings are equivalent, and "NO"
(without the quotes) otherwise.
aaba
abaa
YES
aabb
abab
NO
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".
题目看错了666
能分就分,且把字典序小的排前面
#include<bits/stdc++.h>
using namespace std; string equ(string s)
{
int n=s.length();
if (n&1) return s;
string s1= equ(s.substr(0,n/2));
string s2= equ(s.substr(n/2,n/2));
if (s1<s2) return s1+s2;
return s2+s1;
}
string s1,s2;
int main()
{
cin>>s1>>s2;
if (equ(s1).compare(equ(s2))==0)
{
cout<<"YES"<<endl;
}
else cout<<"NO"<<endl;
return 0;
}
CF 559B(Equivalent Strings-构造法)的更多相关文章
- Codeforces 559B - Equivalent Strings
559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...
- Codeforces 559B Equivalent Strings 等价串
题意:给定两个等长串a,b.推断是否等价.等价的含义为:若长度为奇数,则必须是同样串.若长度是偶数,则将两串都均分成长度为原串一半的两个子串al,ar和bl,br,当中al和bl等价且ar和br等价, ...
- codeforces 559b//Equivalent Strings// Codeforces Round #313(Div. 1)
题意:定义了字符串的相等,问两串是否相等. 卡了时间,空间,不能新建字符串,否则会卡. #pragma comment(linker,"/STACK:1024000000,102400000 ...
- Codeforces - 559B - Equivalent Strings - 分治
http://codeforces.com/problemset/problem/559/B 这个题目,分治就好了,每次偶数层可以多一种判断方式,判断它的时间就是logn的(吧),注意奇数层并不是直接 ...
- Codeforces Round #313 (Div. 1) B. Equivalent Strings
Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...
- 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 ...
- Uva 120 - Stacks of Flapjacks(构造法)
UVA - 120 Stacks of Flapjacks Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld &a ...
随机推荐
- 如何在实际项目中使用Promise(入门级)
你们有没有遇到过这样的情况,ES6看过了,Promise的文字概念都懂,但是我要怎么在项目中去写一个Promise呢? 那天我就是带着这样的疑问去网上搜了下.最后成功地在项目中应用了Promise,只 ...
- 【2017 Multi-University Training Contest - Team 6】Kirinriki
[链接]http://acm.hdu.edu.cn/showproblem.php?pid=6103 [题意] 给出一串字符串,从中选出两个不重叠的字符串,使得两个字符串的距离和 <= m 的最 ...
- Activity启动模式的深入分析
网上关于Activity启动模式的文章许多.可是看起来都千篇一律,看完之后我们都能理解这4种启动模式.只是官方api对singleTask这个启动模式解释有些争议,导致我事实上并没有真正理解这几种模式 ...
- jquery中prop()和attr()的使用
jquery1.6+出现的prop()方法. • 对于HTML元素本身就带有的固有属性,在处理时,使用prop方法. • 对于HTML元素我们自己自定义的DOM属性,在处理时,使用attr方法. • ...
- 关于React中,map出来的元素添加事件问题
用es6 map 的写法 直接绑定一个onTouchStart 事件不会报错. 用es5的map写法 如果不加上this 会报这个错误 无法读取未定义的属性 解决的方法是 绑定this 就可以了
- Java Web学习总结(16)——JSP的九个内置对象
一.JSP运行原理 每个JSP 页面在第一次被访问时,WEB容器都会把请求交给JSP引擎(即一个Java程序)去处理.JSP引擎先将JSP翻译成一个_jspServlet(实质上也是一个servlet ...
- Java Web学习总结(12)——使用Session防止表单重复提交
在平时开发中,如果网速比较慢的情况下,用户提交表单后,发现服务器半天都没有响应,那么用户可能会以为是自己没有提交表单,就会再点击提交按钮重复提交表单,我们在开发中必须防止表单重复提交. 一.表单重复提 ...
- JSP与Servlet的介绍说明
什么是Servlet和JSP 用Java开发Web应用程序时用到的技术主要有两种,即Servlet和JSP. Servlet是在服务器端执行的Java程序,一个被称为Servlet容器的程序(其实就是 ...
- [D3] Add label text
If we want to add text to a node or a image // Create container for the images const svgNodes = svg ...
- python 的spyder用法
ctrl+tab可以进行跳转 https://blog.csdn.net/luckygirl0809/article/details/79929491