Codeforces Round #313 (Div. 2) equivalent Strings (search)

Source: Internet
Author: User

The main idea: to determine whether two strings are equivalent.

Equivalent conditions (any one can be satisfied): 1, two strings exactly the same

2, each string into two parts of the same length, if A1 equivalent to B1 and A2 equivalent to B2, or A1 equivalent to B2 and A2 equivalent to B1


Because the equivalence condition is very vague, I have been stuck for a long time. The 2nd rule in the equivalence condition means that if the 22 substrings of the AB two string satisfy both conditions, then AB is equivalent (a bit around, right), and if we have all read the sentence clearly, then obviously we can recursively judge the equivalence.


First, if the length of the two strings is unequal, then it is certainly not equivalent, and if the length of the current string is odd, then we can determine whether the two strings are strictly equivalent. If the current two strings are already strictly equal, there is no need for recursive judgment.

#include <cstdio> #include <cstring> #define MAXN 200005using namespace Std;char a[maxn],b[maxn];int len; BOOL Check (char *s1,char *s2,int len) {int i;if (len%2 = = 1) {for (i = 0; i < len; i++) if (s1[i]! = S2[i]) return False;retur n true;} else//recursive judgment {return (check (S1,S2,LEN/2) &&check (S1+LEN/2,S2+LEN/2,LEN/2)) | | (Check (S1,S2+LEN/2,LEN/2) &&check (S1+LEN/2,S2,LEN/2));}} int main () {scanf ("%s%s", A, b), int len1 = strlen (a), int len2 = strlen (b), if (len1! = len2) {printf ("no\n"); return 0;} if (check (A,B,LEN1)) printf ("yes\n"), Else printf ("no\n");}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces Round #313 (Div. 2) equivalent Strings (search)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.