训练
原题

题目描述
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
inputCopy
aaba
abaa
outputCopy
YES
inputCopy
aabb
abab
outputCopy
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”.

题意

给定两个字符串判等的标准(are called equivalent),即两个串 are equivalent ,或者各自对半分成两个字串,交叉are equivalent满足至少一个条件,则说明两串 are equivalent。
之所以飙英文,是因为直接说“是相等的“会晕,这里的equivalent应理解为等价

思考过程

开始有点困,竟然还以为只用分一次
然后觉得不对劲,但是又把样例的aaba看成了aaab(反正就是看成两个ab),然后迷迷糊糊敲了一堆,才发现又不对劲。。
然后思路出来了,
用4个参数表示两个需要判断等价的字串的首位index,然后描述等价条件分治到底

测奇数长度,莫名其妙会l>r然后一顿乱加条件
然后就wa第22点
最后调的时候才注意到,要分成“two halves of the same size“!!!!

#include <string.h>
#include <cstring>
#include <iostream>
//#include<ctring>using namespace std;
string s1, s2;
bool eql(int l, int r, int ll, int rr) {if (l > r) return 0;if (l == r && (ll == rr)) return s1[l] == s2[ll];int t = 0,x=0;int ls = r - l + 1;for (register int i = 0; i <= ls - 1; i++,x=i) {//判断两个串是否完全相同,如果是奇数,不能分成两段相同长度的串,但如果完全相等也合法if (s1[i + l] != s2[i + ll]) break;t = i;//如果加到i++后面,就会跟着i在最后一次循环后+1!!!!!}if (t == ls - 1) return 1;if (ls % 2) return 0;int mid1 = (l + r) / 2;if (eql(l, mid1, ll, mid2) && eql(mid1 + 1, r, mid2 + 1, rr)) return 1;//对应eqlif (eql(l, mid1, mid2 + 1, rr) && eql(mid1 + 1, r, ll, mid2)) return 1;//交叉eqlreturn 0;
}
int main() {cin >> s1 >> s2;int l1 = s1.length(), l2 = s2.length();s1 = " " + s1, s2 = " " + s2;if (eql(1, l1, 1, l1))cout << "YES";elsecout << "NO";
}

CF 559B Equivalent Strings 分治05 A题相关推荐

  1. 【CodeForce】559B Equivalent Strings 等效字符串

    [CodeForce]559B Equivalent Strings 等效字符串 B. Equivalent Strings time limit per test2 seconds memory l ...

  2. Codeforces Round #313 (Div. 1) B. Equivalent Strings

    Equivalent Strings Problem's Link:   http://codeforces.com/contest/559/problem/B  Mean: 给定两个等长串s1,s2 ...

  3. 【CF 600E】Lomsat gelral(树上启发式合并, dsu on tree, 静态链分治,模板题)

    Algorithm 名称:树上启发式合并, dsu on tree, 静态链分治 用处:一般用来解决一类不带修改的子树查询问题 核心思想为:利用重链剖分的性质优化子树贡献的计算. 前置知识:启发式合并 ...

  4. 【POJ - 1741】Tree(树分治,容斥,点分治,模板题)

    题干: Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist ...

  5. codeforces 112APetya and Strings(字符串水题)

    A. Petya and Strings 点击打开题目 time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. 根号分治练手题 西比拉先知系统 题解

    西比拉先知系统 题目描述 [数据范围] n,m,Q≤3×105,y≤1000n,m,Q \leq 3 \times 10^5 , y \leq 1000n,m,Q≤3×105,y≤1000 具体做法与 ...

  7. cf 923D Picking Strings

    一 原题 E. Picking Strings time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  8. CF思维联系–CodeForces-217C C. Formurosa(这题鸽了)

    ACM思维题训练集合 The Bytelandian Institute for Biological Research (BIBR) is investigating the properties ...

  9. 牛客练习赛50 F.tokitsukaze and Another Protoss and Zerg(分治+NTT)(模板题)

    题目 在n场1v1中,假设第i场,有ai个星灵单位,和bi个虫族单位. tokitsukaze可以在一场1v1中,任选一种种族进行游戏. 如果选择了星灵,那么在这场游戏中,可以选择出兵1到ai个单位. ...

  10. 递归、分治算法刷题笔记

    递归 确定递归函数的参数和返回值: 确定哪些参数是递归的过程中需要处理的,那么就在递归函数里加上这个参数, 并且还要明确每次递归的返回值是什么进而确定递归函数的返回类型 确定终止条件: 写完了递归算法 ...

最新文章

  1. python3语法错误-【Python3之异常处理】
  2. 戴尔服务:为企业转型导航
  3. 图卷积网络是什么?(行为识别)
  4. access 日期交集_Access重要知识点
  5. 微型计算机接口技术2018真题,2018年微机原理及接口技术复习题.doc
  6. Linux内存管理:Swap介绍以及如何使交换具有可扩展性
  7. Javascript的数组对象
  8. Git命令集十四——抓取命令
  9. LeetCode 22. Generate Parentheses
  10. java 实现多重继承
  11. 全球各国家手机号正则校验
  12. 腾讯AI Lab招聘实习生(内推)
  13. 商标注册服务的详细讲解
  14. python 打开网页并截图_python 使用默认浏览器打开,截图内容,并识别内容
  15. Windows10 LTSB/LTSC版安装应用商店与UWP
  16. 关于uni.appd打包H5 图片在IOS 上不显示的问题
  17. python redis缓存_第二百九十五节,python操作redis缓存-字符串类型
  18. thymeleaf引用图片_thymeleaf显示图片(转)
  19. 失眠怎么办?不妨试试这五款好物
  20. 迅雷下载文件名为download的解决办法

热门文章

  1. 常用sql语句及案例(oracle)
  2. 分享15款很棒的 JavaScript 开发工具
  3. Newtonsoft.Json报错:未能加载文件或程序集...或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配...
  4. 微信小程序(一) 入门
  5. Solr进阶之Solr综合文本相似度的多因素权重排序实现
  6. 自制TXT文本分割工具
  7. 在SQLServer2005中使用全文搜索
  8. Java过滤emoji表情,找出emoji的unicode范围。
  9. 为什么要使用自增ID作为主键
  10. Leetcode 76.最小覆盖子串