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. mysql查询表基本操作

    数据库表的创建create table <表名>( <列名> <数据类型及长度> [not null], <列名> <数据类型及长度>, . ...

  2. winfrom 下 listbox 选项添加value

    public struct MyItem { public string Name; public string Tag; public override string ToString() { re ...

  3. zookeeper简单实战

    一.安装(单机模式.集群模式.伪集群模式) 1:安装JDK 2:解压zk压缩包 3:在conf目录下创建zoo.cfg配置文件. 设置超时时间,快照目录,事务日志文件目录,对外端口,服务IP 4:启动 ...

  4. 使用PowerMockito 对静态类进行mock

    Mock的中文的意思就是模拟,Mockito是mock的扩展,但是Mockito并不支持对静态类的mock,所以我们引入PowerMockito实现对静态类的mock. 首先pom添加PowerMoc ...

  5. 把kafka数据从hbase迁移到hdfs,并按天加载到hive表(hbase与hadoop为不同集群)

    需求:由于我们用的阿里云Hbase,按存储收费,现在需要把kafka的数据直接同步到自己搭建的hadoop集群上,(kafka和hadoop集群在同一个局域网),然后对接到hive表中去,表按每天做分 ...

  6. EasyUI+bootsrtap混合前端框架

    EasyUI+bootsrtap混合前端框架 http://www.jeasyui.com/download/index.php用户没有登录前浏览的页面用bootsrtap框架用户登录进去后的商家管理 ...

  7. JS方法的使用

    $("#yingxiang_id li").each(function () { if ($(this).find(".div-relative").attr( ...

  8. P4281 [AHOI2008]紧急集合 / 聚会

    P4281 [AHOI2008]紧急集合 / 聚会 lca 题意:求3个点的lca,以及3个点与lca的距离之和. 性质:设点q1,q2,q3 两点之间的lca t1=lca(q1,q2) t2=lc ...

  9. Android MediaPlayer 操作

  10. 05: python中的函数

    1.1 python 函数   1.函数作用 定义: 函数是指将一组语句的集合通过一个名字(函数名)封装起来,要想执行这个函数,只需调用其函数名即可 特性: 减少重复代码 使程序变的可扩展 使程序变得 ...