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. VS中代码对齐等快捷键

    在VS2008中,选定代码后,按Ctrl+K+F组合键,可以自动进行代码对齐. 注意:要先按下Ctrl和K,再按下F,因为Ctrl+F是查找的快捷键. 也可以先按下Ctrl+K,再按下Ctrl+F. ...

  2. arcgis中加载google在线地图

    打开arcmap——文件——arcgis online ——搜索china maps 选择china

  3. Object-C-NSFileHandle

    NSFileHandle 类中得到方法可以很方便的对文件数据进行读写.追加,以及偏移量的操作. NSFileHandle 基本步骤: 1.打开文件,获取一个NSFileHandle 对象 2.对打开N ...

  4. Spring,Struts2,MyBatis,Activiti,Maven,H2,Tomcat集成(四)——Activiti集成

    1.添加Activiti Maven依赖: <!-- ==============================activiti=========================== --&g ...

  5. NIO_2

    导语 缓冲器的设计的是新IO模型中最基础的一部分.因为新IO模型中要求所有的IO操作都需要进行缓冲.在新的IO模型中,不再向输出流写入数据和从数据流中读取数据了,而是要从缓冲区中读写数据.缓冲区可是是 ...

  6. 网站app原型设计工具:axure,Mockups,墨刀

    网站app原型设计工具:axure,Mockups,墨刀 Balsamiq Mockups 3 网站原型设计工具非常高效,非常简单,几分钟就能搞定比axure好用很多 墨刀 - 免费的移动应用原型与线 ...

  7. C/C++之内存分配

    一.编译时与运行时的内存情况1.编译时不分配内存编译时是不分配内存的.此时只是根据声明时的类型进行占位,到以后程序执行时分配内存才会正确.所以声明是给编译器看的,聪明的编译器能根据声明帮你识别错误.2 ...

  8. web前端----jQuery扩展(很重要!!)

    1.jQuery扩展语法 把扩展的内容就可以写到xxxx.js文件了,在主文件中直接导入就行了. 用法1.$.xxx() $.extend({ "GDP": function () ...

  9. linux环境下安装jdk1.6

    卸载rpm版的jdk: #rpm -qa|grep jdk 显示:jdk1.6.0_29-fcs 卸载:#rpm -e --nodeps jdk1.6.0_29-fcs 1.从sun公司网站www.s ...

  10. 利用构建缓存机制缩短Docker镜像构建时间

    在使用Docker部署PHP或者node.js应用时,常用的方法是将代码和环境镜像打包成一个镜像然后运行,一些云厂商提供了非常便捷的操作,只需要把我们的代码提交到VCS上,然后它们就会帮我们拉取代码并 ...