感觉题意不太好懂 = =#

给两个字符串 问是否等价
等价的定义(满足其中一个条件):1.两个字符串相等 2.字符串均分成两个子串,子串分别等价

因为超时加了ok函数剪枝,93ms过的。

#include <iostream>
#include <cstring>
#define clr(x,c) memset(x,c,sizeof(x))
using namespace std; const int N = 200005;
char s[N], t[N];
int sc[30], tc[30]; bool ok(char s[], char t[], int len)
{
clr(sc, 0); clr(tc, 0);
for (int i = 0; i < len; ++i) {
sc[ s[i] - 'a' ]++;
tc[ t[i] - 'a' ]++;
}
for (int i = 0; i < 26; ++i) {
if (sc[i] != tc[i]) return false;
}
return true;
} bool equ(char s[], char t[], int len)
{
if (!strncmp(s, t, len)) return true;
if (len % 2) return false; if (!ok(s, t, len)) return false; int l = len / 2;
if (equ(s, t, l) && equ(s + l, t + l, l)) return true;
if (equ(s, t + l, l) && equ(s + l, t, l)) return true;
return false;
} int main()
{
std::ios::sync_with_stdio(false);
while (cin >> s >> t) {
if (equ(s, t, strlen(s))) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}

  

Codeforces Round #313 (Div. 2) D.Equivalent Strings (字符串)的更多相关文章

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

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

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

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

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

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

  5. Codeforces Round #313 (Div. 2)(A,B,C,D)

    A题: 题目地址:Currency System in Geraldion 题意:给出n中货币的面值(每种货币有无数张),要求不能表示出的货币的最小值.若全部面值的都能表示,输出-1. 思路:水题,就 ...

  6. Codeforces Round #313 (Div. 2) 解题报告

    A. Currency System in Geraldion: 题意:有n中不同面额的纸币,问用这些纸币所不能加和到的值的最小值. 思路:显然假设这些纸币的最小钱为1的话,它就能够组成随意面额. 假 ...

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

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

  8. Codeforces Round #313 (Div. 2) A.B,C,D,E Currency System in Geraldion Gerald is into Art Gerald's Hexagon Equivalent Strings

    A题,超级大水题,根据有没有1输出-1和1就行了.我沙茶,把%d写成了%n. B题,也水,两个矩形的长和宽分别加一下,剩下的两个取大的那个,看看是否框得下. C题,其实也很简单,题目保证了小三角形是正 ...

  9. Codeforces Round #302 (Div. 1) C. Remembering Strings DP

    C. Remembering Strings Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

随机推荐

  1. ModelState用法

    ModelState.AddModelError:添加错误信息 ModelState是一个字典类型,这句话的作用是向ModelState中添加一条错误信息,第一个参数是Key,第二个参数是Value. ...

  2. tableView -- tips

    1. 如果发现TableView的第一个sectionHeader不显示, 那么可以断定, 你没有用代理方法来设置 sectionHeader的高度! #pragma mark - delegate ...

  3. Linux查看用户和组命令

    在Linux系统里,我们会经常用Linux查看用户的命令,在这里我们一些命令进行了总结,总共有7个,并做了详细的解释,以便让大家更深入的理解,接下来让我们一起来看看这些命令和具体应用. 一.Linux ...

  4. backbone案例

    http://www.kuqin.com/webpagedesign/20120807/324101.html http://udonmai.com/code/todos-backbone%E6%A1 ...

  5. SQL 中With as 的用法

    转自:http://www.cnblogs.com/superyinhai/archive/2010/04/09/1708643.html 一.WITH AS的含义 WITHAS短语,也叫做子查询部分 ...

  6. UINavigationController使用的注意事项

    1.常用属性viewControllers //所有在栈中的控制器topViewController //栈顶控制器navigationBar //导航栏 竖屏下默认44,横屏默认32 2.对navi ...

  7. asp.net将sql语句封装在类库中

    将sql语句封装在cs中,通过类库的引用使用他的select.update.insert 源代码(cs): using System; using System.Collections.Generic ...

  8. asp中将文本框内的日期转换成datetime类型的数据

    将字符类型的日期转化为DateTime类型主要有以下方法: 方法一:Convert.ToDateTime(string) string格式有要求,必须是yyyy-MM-dd hh:mm:ss 方法二: ...

  9. 乐1/MACBOOK/ N1 Type-C接口新体验

    经过在华强北电子市场排队一个小时,笔者顺利买到了期待已久的乐1,结合之前的NOKIA平板电脑N1,苹果全新MACBOOK,终于集齐了手机.平板.笔记本电脑三种TYPE-C接口设备(能兑换极品装备吗?^ ...

  10. 【Xamarin挖墙脚系列:IOS-关于手机支持的屏幕方向】

    原文:[Xamarin挖墙脚系列:IOS-关于手机支持的屏幕方向] 设置支持的屏幕方向有两个级别,一个是app级别的,另一个是viewController级别的. app 级别的可以在[target] ...