CF559B Equivalent Strings 题解

题目描述

吐槽一下,题目翻译有歧义。

思路分析

你会发现,当你需要判断字符串 \(a,b\) 是否等价时,如果长度为偶数,需要继续判断字符串 \(a\) 拆分的字串。

所用知识

s.substr(i,j)//在字符串s中,从位置i开始截取长度为j的字串

参考代码

#include <bits/stdc++.h>
using namespace std;
namespace Raiden
{
bool check(string a,string b)//判断a、b是否等价
{
int lena=a.size();
if(lena%2)// 如果长度为奇数
{
return a==b;// a、b等价即为字符串相等
}
else//否则长度为偶数
{
//a分成两段
string s1=a.substr(0,lena/2);//前半段
string s2=a.substr(lena/2,lena/2);//后半段
//b分成两段
string s3=b.substr(0,lena/2);//前半段
string s4=b.substr(lena/2,lena/2);//后半段 return (check(s1,s4)&&check(s2,s3))||(check(s1,s3)&&check(s2,s4));
}
}
int work()
{
string a,b;
cin>>a>>b;
cout<<(check(a,b)?"YES":"NO")<<endl;
return 0;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
return Raiden::work();
}

题解:CF559B Equivalent Strings的更多相关文章

  1. CF559B Equivalent Strings TJ

    前言 题目传送门 正解:模拟,递归. 考试的 T4,还是想复杂了 qwq. 这题不要用 STL,容易 \(\texttt{TLE}\)!! 题意简述 翻译够简了. 对了给一下样例解释的翻译: 第一个样 ...

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

    D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/ ...

  3. Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力

    B. Equivalent Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559 ...

  4. Equivalent Strings (字符串相等?)

    Equivalent Strings   E - 暴力求解.DFS Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I ...

  5. Equivalent Strings

    Equivalent Strings 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/E 题意: 给出 ...

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

    Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...

  7. Codeforces 559B - Equivalent Strings

    559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...

  8. Codeforces Round #313 D. Equivalent Strings(DFS)

    D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  9. Codeforces Round #313 (Div. 2) 560D Equivalent Strings(dos)

    D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  10. 【24.34%】【codeforces 560D】Equivalent Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. 使用image-syncer镜像同步工具将阿里云镜像仓库镜像迁移至私有Harbor

    借助于阿里云开源的镜像同步工具image-syncer实现harbor及阿里云镜像仓库之间的镜像迁移 下载镜像同步工具 curl -fL "https://wiseo-generic.pkg ...

  2. JavaScript设计模式样例十四 —— 观察者模式

    观察者模式(Observer Pattern) 定义:当一个对象被修改时,则会自动通知它的依赖对象.目的:定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都得到通知并被 ...

  3. 使用FModel提取黑神话悟空的资产

    目录 前言 设置 效果展示 闲聊 可能遇到的问题 没有相应的UE引擎版本选项 前言 黑神话悟空昨天上线了,解个包looklook. 本文内容比较简洁,仅介绍解包黑神话所需的专项配置,关于FModel的 ...

  4. Centos8下Redis设置Session共享存储

    Redis-Session共享存储 前提条件: 1.安装Redis 2.安装Apache或Nginx 3.安装php 本机环境: php:7.3 Redis:5.0.7 开始部署: 我是分别用Cent ...

  5. python pyqt6 设定窗口置顶

    self.setWindowFlag(Qt.WindowType.WindowStaysOnTopHint)即可效果一般,页面会出现闪烁一次, # 置顶按钮 self.top_button = QPu ...

  6. 第二章:智能Agent

    第二章:智能Agent 本章讨论Agent的本质,Agent是否完美,环境的多样性,及由此带来的各种Agent分类. 1. Agnet和环境 Agent通过传感器感知环境并通过执行器对所处环境产生影响 ...

  7. C# Dynamic 转换成 Dictionary,Dynamic 转换成 DataTable

    部分软件开发的时候用到了 dynamic 类型,这个类型的数据不需要做其他处理的时候非常好用,但是需要对其中的数据调整的时候就不是那么好用了,这里提供两个常见的转换方式 Dynamic To Dict ...

  8. 手撸MQ消息队列——循环数组

    队列是咱们开发中经常使用到的一种数据结构,它与栈的结构类似.然而栈是后进先出,而队列是先进先出,说的专业一点就是FIFO.在生活中到处都可以找到队列的,最常见的就是排队,吃饭排队,上地铁排队,其他就不 ...

  9. 从0到1搭建权限管理系统系列三 .net8 JWT创建Token并使用

    说明 该文章是属于OverallAuth2.0系列文章,每周更新一篇该系列文章(从0到1完成系统开发). 该系统文章,我会尽量说的非常详细,做到不管新手.老手都能看懂. 说明:OverallAuth2 ...

  10. centos7安装MySQL及远程配置

    #下载mysql源安装包 shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm #安装m ...