zoukankan      html  css  js  c++  java
  • 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], tc[30];
    
    bool ok(char s[], char t[], int len)
    {
        clr(sc, 0); clr(tc, 0);
        for (int i = 0; i < len; ++i) {
            sc[ s[i] - 'a' ]++;
            tc[ t[i] - 'a' ]++;
        }
        for (int i = 0; i < 26; ++i) {
            if (sc[i] != tc[i]) return false;
        }
        return true;
    }
    
    bool equ(char s[], char t[], int len)
    {
        if (!strncmp(s, t, len)) return true;
        if (len % 2) return false;
    
        if (!ok(s, t, len)) return false;
    
        int l = len / 2;
        if (equ(s, t, l) && equ(s + l, t + l, l)) return true;
        if (equ(s, t + l, l) && equ(s + l, t, l)) return true;
        return false;
    }
    
    int main()
    {
        std::ios::sync_with_stdio(false);
        while (cin >> s >> t) {
            if (equ(s, t, strlen(s))) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    面向对象介绍
    常用模块2
    常用模块1
    常用模块3
    模块导入以及常用模块
    模块介绍
    Astra: Apache Cassandra的未来是云原生
    麦格理银行借助DataStax Enterprise (DSE) 驱动数字化转型
    Apache Cassandra使用报告2020
    比较Apache Cassandra的压力测试工具
  • 原文地址:https://www.cnblogs.com/wenruo/p/5142264.html
Copyright © 2011-2022 走看看