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
  • 相关阅读:
    使用 GPUOperator 与 KubeSphere 简化深度学习训练与 GPU 监控
    基于 WeDataSphere Prophecis 与 KubeSphere 构建云原生机器学习平台
    在 Kubernetes Pod 中如何获取客户端的真实 IP
    云原生的 WebAssembly 能取代 Docker 吗?
    KubeSphere 开源 KubeEye:Kubernetes 集群自动巡检工具
    对于 Serverless, DevOps, 多云及边缘可观察性的思考与实践
    终于可以像使用 Docker 一样丝滑地使用 Containerd 了
    你真的理解 Kubernetes 中的 requests 和 limits 吗?
    顶点(vertexs) 图元(primitives) 片元(fragments片断) 像素(pixels)
    GLUT回调函数
  • 原文地址:https://www.cnblogs.com/zxhl/p/4669172.html
Copyright © 2011-2022 走看看