559B - Equivalent Strings

思路:字符串处理,分治

不要用substr(),会超时

AC代码:

#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define ll long long
const int N=2e5+;
bool cmp(char a[],char b[],int l)
{
bool ans=true;
for(int i=;i<l;i++)if(a[i]!=b[i])ans=false;
return ans;
}
bool eq(char a[],char b[],int l)
{
if(cmp(a,b,l))return true;
if(l&)return false;
if(eq(a,b+l/,l/)&&eq(a+l/,b,l/)||eq(a,b,l/)&&eq(a+l/,b+l/,l/))return true;
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
char s1[N],s2[N];
cin>>s1>>s2;
if(eq(s1,s2,strlen(s1)))cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return ;
}

TLE代码:

#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define ll long long
bool eq(string a,string b)
{
if(a==b)return true;
if(a.size()!=b.size())return false;
if(a.size()&)return false;
string a1=a.substr(,a.size()/),a2=a.substr(a.size()/,a.size()/);
string b1=b.substr(,b.size()/),b2=b.substr(b.size()/,b.size()/);
if((eq(a1,b1)&&eq(a2,b2))||(eq(a1,b2)&&eq(a2,b1)))return true;
else return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
string s1,s2;
cin>>s1>>s2;
if(eq(s1,s2))cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return ;
}

Codeforces 559B - Equivalent Strings的更多相关文章

  1. Codeforces - 559B - Equivalent Strings - 分治

    http://codeforces.com/problemset/problem/559/B 这个题目,分治就好了,每次偶数层可以多一种判断方式,判断它的时间就是logn的(吧),注意奇数层并不是直接 ...

  2. codeforces 559b//Equivalent Strings// Codeforces Round #313(Div. 1)

    题意:定义了字符串的相等,问两串是否相等. 卡了时间,空间,不能新建字符串,否则会卡. #pragma comment(linker,"/STACK:1024000000,102400000 ...

  3. Codeforces 559B Equivalent Strings 等价串

    题意:给定两个等长串a,b.推断是否等价.等价的含义为:若长度为奇数,则必须是同样串.若长度是偶数,则将两串都均分成长度为原串一半的两个子串al,ar和bl,br,当中al和bl等价且ar和br等价, ...

  4. CodeForces - 560D Equivalent Strings

    Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings ...

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

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

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

    D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/ ...

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

  8. Codeforces Round #313 D. Equivalent Strings(DFS)

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

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

随机推荐

  1. JaveScript-简介

    1.JaveScript:脚本语言.(弱类型语言)可以写在head,也可以写在head里,同样可以写在html外面<script src=""></script& ...

  2. Object之equals和hashCode

    译者注 :你可能会觉得Java很简单,Object的equals实现也会非常简单,但是事实并不是你想象的这样,耐心的读完本文,你会发现你对Java了解的是如此的少.如果这篇文章是一份Java程序员的入 ...

  3. Mysql的group by语句

    如上图查询结果,因为group by后面的字段是的分组的依据字段,所以select子句中只有是group by后面的字段,或者是聚集函数才有意义.然而mysql居然可以在select子句中出现不在gr ...

  4. python 文件写入与储存

    python使用open()这个函数来打开文件返回对象: open 第二参数 "r" 以只读方式打开文件 "w" 以写入方法打开文件,会覆盖已储存的内容 &qu ...

  5. CAEAGLLayer

    CAEAGLLayer 当iOS要处理高性能图形绘制,必要时就是OpenGL.应该说它应该是最后的杀手锏,至少对于非游戏的应用来说是的.因为相比Core Animation和UIkit框架,它不可思议 ...

  6. linux服务器---安装swat

    安装swat swat是一个图形化的samba管理软件,可以帮助不熟悉的人去灵活的配置samba服务, 1.安装swat [root@localhost wj]#yum install -y samb ...

  7. P1283 平板涂色

    P1283 平板涂色 dfs 记忆化搜索 将矩阵转化为图求解,然后我们发现这是个DAG,于是就可以愉快地跑搜索了. 进行dfs时,我们可以用类似拓扑排序的方法.每次将上面所有矩形都被刷过(入度in[ ...

  8. CentOS7.3防火墙firewalld简单配置

    今天安装了centos7.3, 想用iptables的save功能保存规则的时候发现跟rhel不一样了,  后来度娘说centos用的是firewalld而不是iptables了, 平时工作都是用re ...

  9. CF#338D. GCD Table

    传送门 简单的中国剩余定理练习. 首先行数一定是$lcm$,然后只要确定最小的列数就能判定解合不合法了. 我们可以得到线性模方程组: $y \equiv 0 \pmod{a_1}$ $y+1 \equ ...

  10. 20145312袁心《网络对抗》Web基础实践

    20145312袁心<网络对抗>Web基础实践 问题回答 1.什么是表单: 表单在网页中主要负责数据采集功能. 一个表单有三个基本组成部分: 表单标签:这里面包含了处理表单数据所用CGI程 ...