Codeforces Round #313 (Div. 2) D.Equivalent Strings (字符串)
感觉题意不太好懂 = =#
给两个字符串 问是否等价
等价的定义(满足其中一个条件):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 (字符串)的更多相关文章
- 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 (Div. 2) 560D Equivalent Strings(dos)
D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #313 (Div. 2)(A,B,C,D)
A题: 题目地址:Currency System in Geraldion 题意:给出n中货币的面值(每种货币有无数张),要求不能表示出的货币的最小值.若全部面值的都能表示,输出-1. 思路:水题,就 ...
- Codeforces Round #313 (Div. 2) 解题报告
A. Currency System in Geraldion: 题意:有n中不同面额的纸币,问用这些纸币所不能加和到的值的最小值. 思路:显然假设这些纸币的最小钱为1的话,它就能够组成随意面额. 假 ...
- codeforces 559b//Equivalent Strings// Codeforces Round #313(Div. 1)
题意:定义了字符串的相等,问两串是否相等. 卡了时间,空间,不能新建字符串,否则会卡. #pragma comment(linker,"/STACK:1024000000,102400000 ...
- 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题,其实也很简单,题目保证了小三角形是正 ...
- 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 ...
随机推荐
- 【Base64】JDK里面实现Base64的API
原文出处: 成熟的毛毛虫的博客 BASE64 编码是一种常用的字符编码,在很多地方都会用到.但base64不是安全领域下的加密解密算法.能起到安全作用的效果很差,而且很容易破解,他核心作用应该是传输数 ...
- Oracle本地,远程,分布式登录
identify认证,确定; identity同一性,个性; 本地连接 sqlplus scott/tiger@localhost:1521/orcl 这句话就等于sqlplus scott/tige ...
- AngularJs项目
AngularJs项目实践总结 今年3月接触AngularJs,并且在6月的项目中开始应用,从踩坑到填坑花了不少时间,根据项目中的实际应用情况总结了一些经验,如下: 一.UI控件选择 Angularj ...
- hdu 1255 覆盖的面积 (线段树处理面积覆盖问题(模板))
http://acm.hdu.edu.cn/showproblem.php?pid=1255 覆盖的面积 Time Limit: 10000/5000 MS (Java/Others) Memo ...
- hdu 3303 Harmony Forever (线段树 + 抽屉原理)
http://acm.hdu.edu.cn/showproblem.php?pid=3303 Harmony Forever Time Limit: 20000/10000 MS (Java/Othe ...
- 被FBI点名的中国黑客-Lion
网名:Lion(狮子) 真实姓名:林勇 QQ:21509 简介:红客联盟创始人(该组织在2001年5月的黑客大战中一举成名,会员人数最多时达到6万,很有影响力),现在安氏因特网安全系统(中国) ...
- sql 中 case when 语法(转)
sql语言中有没有类似C语言中的switch case的语句?? 没有,用case when 来代替就行了. 例如,下面的语句显示中文年月 select ...
- wordpress的使用
ubuntu 发送邮件学习资料: http://edu.51cto.com/lesson/id-6066.html 相关插件: Disable Google Fonts 使用中出现的问题: 1:wor ...
- Android 自定义对话框(Dialog)位置,大小
代码: package angel.devil; import android.app.Activity; import android.app.Dialog; import android.os.B ...
- 【Quick 3.3】资源脚本加密及热更新(二)资源加密
[Quick 3.3]资源脚本加密及热更新(二)资源加密 注:本文基于Quick-cocos2dx-3.3版本编写 一.介绍 在前一篇文章中介绍了代码加密,加密方式是XXTEA.对于资源文件来说,同样 ...