Codeforces Round #313 (Div. 2) D. Equivalent Strings
D. Equivalent Strings
Time Limit: 2 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/559/problem/B
Description
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are calledequivalent in one of the two cases:
- They are equal.
- If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2, then one of the following is correct:
- a1 is equivalent to b1, and a2 is equivalent to b2
- a1 is equivalent to b2, and a2 is equivalent to b1
As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.
Gerald has already completed this home task. Now it's your turn!
Input
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200 000 and consists of lowercase English letters. The strings have the same length.
Output
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
Sample Input
aaba
abaa
Sample Output
YES
aabb
abab
NO
HINT
题意
判断俩字符串是否类似就是说一半的一半是否相同,交换的情况下又是否相同
题解:
暴力
代码
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <vector>
#include <string.h>
using namespace std; typedef __int64 ll;
const int INF = (int)1E9+;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} //*******************************
bool isEqual(char* a,char* b,int len)
{
bool flag=true;
for(int i=;i<len&&flag;i++)
{
if(a[i]!=b[i]) flag=false;
}
if(flag) return true;
if(len&) return false;
return (isEqual(a,b,len/)&&isEqual(a+len/,b+len/,len/))||(isEqual(a+len/,b,len/)&&isEqual(a,b+len/,len/));
} int main()
{
char a[];
char b[];
scanf("%s%s",a,b);
int len=strlen(a);
if(len%)
{
if(strcmp(a,b)==)
{
printf("YES\n");
}
else printf("NO\n");
return ;
}
if(isEqual(a,b,len))
{
printf("YES\n");
}
else printf("NO\n"); return ;
}
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. 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) D.Equivalent Strings (字符串)
感觉题意不太好懂 = =# 给两个字符串 问是否等价等价的定义(满足其中一个条件):1.两个字符串相等 2.字符串均分成两个子串,子串分别等价 因为超时加了ok函数剪枝,93ms过的. #includ ...
- 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 ...
随机推荐
- [整理]Web应用安全学习
最近在复习TCP/IP相关知识,同时也想对网络安全相关的知识进行系统的补漏. 阅读了一些常见的关于XSS.CSRF等的一些网上文章: http://www.cnblogs.com/luminji/ca ...
- 微信也有土豪版 针对iPhone 6/6 Plus进行优化
土豪们最近都上手iPhone 6/6 Plus了,烦恼的是iPhone 6/Plus增大了屏幕和分辨率,由此带来了不少应用的适配问题,排版乱了,app周边多了一片空白,是不是很煞风景?微信团队昨天放出 ...
- 为dedecms文章列表页标题增加序号,第二页开始才显示第x页
想必大伙建站都会写文章,随着时间的推移,你的智慧结晶会越来越多,一般的建站程序早帮你想好了,把这些文章做成一个列表,比如dedecms栏目列表,便于观众浏览,但有个问题就是dedecms文章列表页标题 ...
- URL编码表,URL编码大全
url编码是一种浏览器用来打包表单输入的格式. 定义 url编码是一种浏览器用来打包表单输入的格式.浏览器从表单中获取所有的name和其中的值 ,将它们以name/value参数编码(移去那些不能传送 ...
- ext3文件系统反删除利器-ext3grep
导读 Linux作为企业级服务器,数据的安全性至关重要,任何数据德尔丢失和误删都是不可容忍的!最近我接触到一款软件-ext3grep,它可以恢复误删的数据,下面简单讲解一下这个软件. ext3grep ...
- 搭建DNS服务器
导读 Linux下架设DNS服务器通常是使用Bind程序来实现的.Bind是一款实现DNS服务器的开放源码的软件.DNS即域名系统,主要功能是将人们易于记忆的Domain Name(域名)与不易记忆的 ...
- [BZOJ1370][Baltic2003]Gang团伙
[BZOJ1370][Baltic2003]Gang团伙 试题描述 在某城市里住着n个人,任何两个认识的人不是朋友就是敌人,而且满足: 1. 我朋友的朋友是我的朋友: 2. 我敌人的敌人是我的朋友: ...
- PHP生成CSV文件
CSV文件的定义这里就不多做介绍了,难能可贵的是用Excel可以直接打开CSV文件.用PHP输出CSV文件本身很简单,但是大家如果有业务需求,下面的代码可以作为参考. $tableheader = a ...
- navicat连接oracle报错ORA-12737: Instant Client Light: unsupported server character set CHS16GBK”
原文如下http://blog.163.com/cp7618@yeah/blog/static/7023477720142154449893/?COLLCC=1318255100& 这个工具可 ...
- DICOM医学图形处理:storescp.exe与storescu.exe源码剖析,学习C-STORE请求(续)
转载:http://blog.csdn.net/zssureqh/article/details/39237649 背景: 上一篇博文中,在对storescp工具源文件storescp.cc和DcmS ...