zoukankan      html  css  js  c++  java
  • 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:

    1. They are equal.
    2. 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:
      1. a1 is equivalent to b1, and a2 is equivalent to b2
      2. 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

    input
    aabb
    abab
    output
    NO

    HINT

    题意

    判断俩字符串是否类似就是说一半的一半是否相同,交换的情况下又是否相同

    题解:

    暴力

    代码

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <vector>
     4 #include <algorithm>
     5 #include <string>
     6 #include <stack>
     7 #include <math.h>
     8 #include <vector>
     9 #include <string.h>
    10 using namespace std;
    11 
    12 typedef __int64 ll;
    13 const int INF = (int)1E9+10;
    14 inline ll read()
    15 {
    16     ll x=0,f=1;char ch=getchar();
    17     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    18     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    19     return x*f;
    20 }
    21 
    22 //*******************************
    23 bool isEqual(char* a,char* b,int len)
    24 {
    25    bool flag=true;
    26     for(int i=0;i<len&&flag;i++)
    27     {
    28         if(a[i]!=b[i]) flag=false;
    29     }
    30     if(flag) return true;
    31     if(len&1) return false;
    32     return (isEqual(a,b,len/2)&&isEqual(a+len/2,b+len/2,len/2))||(isEqual(a+len/2,b,len/2)&&isEqual(a,b+len/2,len/2));
    33 }
    34 
    35 int main()
    36 {
    37       char a[200100];
    38       char b[201000];
    39     scanf("%s%s",a,b);
    40     int len=strlen(a);
    41     if(len%2)
    42     {
    43         if(strcmp(a,b)==0)
    44         {
    45             printf("YES
    ");
    46         }
    47         else printf("NO
    ");
    48         return 0;
    49     }
    50     if(isEqual(a,b,len))
    51     {
    52             printf("YES
    ");
    53         }
    54         else printf("NO
    ");
    55 
    56     return 0;
    57 }
    View Code
  • 相关阅读:
    ABC065D Built[最小生成树]
    loj2718 「NOI2018」归程[Kruskal重构树+最短路]
    BZOJ1821 部落划分[最小生成树]
    BZOJ4777 [Usaco2017 Open]Switch Grass[最小生成树+权值线段树套平衡树]
    CF888G Xor-MST[最小生成树+01trie]
    Atcoder CODE FESTIVAL 2016 Final G
    BZOJ4883 [Lydsy1705月赛]棋盘上的守卫[最小基环树森林]
    BZOJ3714 [PA2014]Kuglarz[最小生成树]
    BZOJ1601 [Usaco2008 Oct]灌水[最小生成树]
    CF892E Envy[最小生成树]
  • 原文地址:https://www.cnblogs.com/zxhl/p/4669172.html
Copyright © 2011-2022 走看看