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

Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent 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 test(s) 
input 
aaba 
abaa 
output 
YES 
input 
aabb 
abab 
output 
NO

题解:爆搜可破

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<queue>
 6 #include<cstring>
 7 #define PAU putchar(‘ ‘)
 8 #define ENT putchar(‘\n‘)
 9 using namespace std;
10 const int maxn=200000+10;
11 char s[maxn],t[maxn];
12 bool dfs(int q,int w,int e,int r){
13     int i,j;for(i=q,j=e;i<=w;i++,j++)if(s[i]!=t[j])break;
14     if(i>w)return true;
15     if(((w-q+1)&1)||((r-e+1)&1))return false;int m1=w+q+1>>1,m2=e+r+1>>1;
16     return (dfs(q,m1-1,m2,r)&&dfs(m1,w,e,m2-1))||(dfs(q,m1-1,e,m2-1)&&dfs(m1,w,m2,r));
17 }
18 inline int read(){
19     int x=0,sig=1;char ch=getchar();
20     for(;!isdigit(ch);ch=getchar())if(ch==‘-‘)sig=0;
21     for(;isdigit(ch);ch=getchar())x=10*x+ch-‘0‘;
22     return sig?x:-x;
23 }
24 inline void write(int x){
25     if(x==0){putchar(‘0‘);return;}if(x<0)putchar(‘-‘),x=-x;
26     int len=0,buf[15];while(x)buf[len++]=x%10,x/=10;
27     for(int i=len-1;i>=0;i--)putchar(buf[i]+‘0‘);return;
28 }
29 void init(){
30     scanf("%s%s",s,t);
31     if(dfs(0,strlen(s)-1,0,strlen(t)-1))puts("YES");
32     else puts("NO");
33     return;
34 }
35 void work(){
36     return;
37 }
38 void print(){
39     return;
40 }
41 int main(){init();work();print();return 0;}
时间: 2024-10-10 20:29:18

Codeforces Round #313 (Div. 1) B.Equivalent Strings的相关文章

Codeforces Round #313 (Div. 2) D. Equivalent Strings 解题心得

原题: Description Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases: They are equal. If we split string a into two halves of the sam

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],

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

运气不错,这次cf大涨,居然是房间第二(要不是D题TLE了,就第一了) 用string会TLE,用char加下标,还看到更牛的算法, 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int maxx=200010; 6 char a[maxx],b[maxx]; 7 bool cmp(int p1,int p2,int len) 8 {

Codeforces Round #313 (Div. 2) Gerald&#39;s Hexagon

给出一个六边形六条边的长度(六边形的每个角为120度),求出这个六边形中边长为1的等边三角形有多少个 由于每个角都是120度并且上下两条边是平行的,因此我们可以补出一个矩形,再减掉周边四个角的面积,用剩下面积除以每个小三角形的面积. #include<cstdio> using namespace std; double a,b,c,d,e,f; int main() { <span style="white-space:pre"> </span>s

Codeforces Round #313 (Div. 2) C Gerald&#39;s Hexagon 计数

// Codeforces Round #313 (Div. 2) C Gerald's Hexagon // 计数 // 关键是平行于a1的长度为1的有多少条,中间的这些*2,再加上a1 // 和a4,就是三角形的总和 // 还是挺简单的,注意递增的初始值,和变化,就ac了 #include <cstdio> #include <algorithm> #include <iostream> #include <cstring> using namespac

Codeforces Round #313 (Div. 1)

官方英文题解:http://codeforces.com/blog/entry/19237 Problem A: 题目大意: 给出内角和均为120°的六边形的六条边长(均为正整数),求最多能划分成多少个边长为1的正三角形. 题解: 把六边形补全变成一个正三角形,然后减去三个角的正三角形即可. Problem B: 题目大意: 给出长度相等的两个串AB,定义两个串相等 当且仅当  A=B  或者  当长度为偶数时,A[1...n/2]=B[1...n/2]  && A[n/2+1...n]=

Codeforces Round #313 (Div. 2) (ABCD题解)

比赛链接:http://codeforces.com/contest/560 水笔场... A. Currency System in Geraldion time limit per test:2 seconds memory limit per test:256 megabytes A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several va

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

A. Currency System in Geraldion: 题意:有n中不同面额的纸币,问用这些纸币所不能加和到的值的最小值. 思路:显然假设这些纸币的最小钱为1的话,它就能够组成随意面额. 假设这些纸币的最小值大于1,那么它所不能组成的最小面额就是1.所以自学求最小值就可以. 我的代码: #include <set> #include <map> #include <cmath> #include <stack> #include <queue

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

A题: 题目地址:Currency System in Geraldion 题意:给出n中货币的面值(每种货币有无数张),要求不能表示出的货币的最小值,若所有面值的都能表示,输出-1. 思路:水题,就是看看有没有面值为1的货币,如果有的话,所有面值的货币都可以通过1的累加得到,如果没有的话,最小的不能表示的就当然是1辣. #include <stdio.h> #include <math.h> #include <string.h> #include <stdli