Codeforces 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的更多相关文章
- Codeforces - 559B - Equivalent Strings - 分治
http://codeforces.com/problemset/problem/559/B 这个题目,分治就好了,每次偶数层可以多一种判断方式,判断它的时间就是logn的(吧),注意奇数层并不是直接 ...
- codeforces 559b//Equivalent Strings// Codeforces Round #313(Div. 1)
题意:定义了字符串的相等,问两串是否相等. 卡了时间,空间,不能新建字符串,否则会卡. #pragma comment(linker,"/STACK:1024000000,102400000 ...
- Codeforces 559B Equivalent Strings 等价串
题意:给定两个等长串a,b.推断是否等价.等价的含义为:若长度为奇数,则必须是同样串.若长度是偶数,则将两串都均分成长度为原串一半的两个子串al,ar和bl,br,当中al和bl等价且ar和br等价, ...
- CodeForces - 560D Equivalent Strings
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings ...
- Codeforces Round #313 (Div. 1) B. Equivalent Strings
Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...
- 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 ...
- Codeforces Round #313 D. Equivalent Strings(DFS)
D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 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 ...
随机推荐
- Filter—过滤器和拦截器的区别
1.首先要明确什么是拦截器.什么是过滤器 1.1 什么是拦截器: 拦截器,在AOP(Aspect-Oriented Programming)中用于在某个方法或字段被访问之前,进行拦截然后在之前或之后加 ...
- uva1494 最小生成树--例题
这题说的是n个城市 建路 使他们联通然后 , 可以使用一条超级的路这条路不计入总长,此时路长度为B, 这条路链接的两个城市人口与和为A+B, 然后计算出最大的A/B 解题 先生成一颗最小生成树,然后 ...
- MySQL从删库到跑路_高级(二)——自定义函数
作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.自定义函数简介 自定义函数(user-defined function UDF)是一种对MySQL扩展的途径,其 ...
- Sa身份登陆SQL SERVER失败的解决方案
经常使用windows身份登陆,久而久之,基本不动怎么用SQL SERVER身份验证登陆,所以趁着有空,就解决一下一些问题~~ 解决方案: 第一步:打开SSMS,先使用windows身份登陆,右击服 ...
- Python 运算符与基本数据类型
一.运算符 1.算数运算: 2.比较运算: 3.赋值运算: 4.逻辑运算: 5.成员运算: 二.基本数据类型 1.空(None) 表示该值是一个空对象,空值是Python里一个特殊的值,用None表示 ...
- Java 简明教程
本文为 Java 的快速简明教程,主要用于快速了解.学习和复习java的语法特点. // 单行注释 /* 多行注释 */ /** JavaDoc(Java文档)注释是这样的.可以用来描述类和类的属性. ...
- MySQL数据库总结
引擎 查看MySQL默认引擎:show variables like '%storage_engine%'; 查看表引擎:show table status from 数据库名; 修改表引擎alter ...
- Nodejs学习笔记(四)与MySQL交互(felixge/node-mysql)
原文链接:http://www.cnblogs.com/zhongweiv/p/nodejs_mysql.html 介绍使用felixge/node-mysql进行SQL的增删改查以及断线重连等操作.
- noip2008 真题练习 2017.2.25
不是有很多可以说的,记住不能边算边取min Code #include<iostream> #include<fstream> #include<sstream> ...
- 【转】各种消息下wParam及lParam值的含义
转载自:http://bbs.fishc.com/forum.php?mod=viewthread&tid=52668#lastpost 01.WM_PAINT消息 LOWORD(lParam ...