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 ...
随机推荐
- sum_series() 求一列数的指定个数的数和(5个数字的和)
#include <stdio.h> #include <stdarg.h> /*用sum_series() 求一列数的指定个数的数和(5个数字的和)*/ double sum ...
- lettcode-102:Binary Tree Level Order Traversal (Java)
Binary Tree Level Order Traversal 二叉树的层序遍历 两种方式: 1.用两个queue交替表示每一层的节点 2.用两个node,一个表示当前层的最后一个节点,一个表示下 ...
- Maven内置变量
1.Maven内置变量说明: ${basedir} 项目根目录 ${project.build.directory} 构建目录,缺省为target ${project.build.outputDire ...
- MYSQL SHOW VARIABLES简介
原文地址:http://www.2cto.com/database/201108/100546.html mysqld服务器维护两种变量.全局变量影响服务器的全局操作.会话变量影响具体客户端连接相关操 ...
- *[topcoder]TheTree
http://community.topcoder.com/stat?c=problem_statement&pm=12746&rd=15703 这道题有意思.给了树的根和每层节点的个 ...
- Android List去掉重复数据
今天用数据库获取数据发现有个字段的数据重复了,于是就写了下面这个方法去除重复的数据. public static List<String> removeDuplicate(List< ...
- Android 性能优化之使用MAT分析内存泄露问题
我们平常在开发Android应用程序的时候,稍有不慎就有可能产生OOM,虽然JAVA有垃圾回收机,但也不能杜绝内存泄露,内存溢出等问题,随着科技的进步,移动设备的内存也越来越大了,但由于Android ...
- Android进阶篇-时间滑动控件
仿Iphone时间选择滑动控件: WheelView.java: /** * @author Administrator * * 时间滑动滚轮 */ public class WheelView ex ...
- oracle database resident connection pooling(驻留连接池)
oracle在11g中引入了database resident connection pooling(DRCP).在此之前,我们可以使用dedicated 或者share 方式来链接数据库,dedic ...
- MapReduce的数据流程、执行流程
MapReduce的数据流程: 预先加载本地的输入文件 经过MAP处理产生中间结果 经过shuffle程序将相同key的中间结果分发到同一节点上处理 Recude处理产生结果输出 将结果输出保存在hd ...