题解:CF559B Equivalent Strings
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的更多相关文章
- CF559B Equivalent Strings TJ
前言 题目传送门 正解:模拟,递归. 考试的 T4,还是想复杂了 qwq. 这题不要用 STL,容易 \(\texttt{TLE}\)!! 题意简述 翻译够简了. 对了给一下样例解释的翻译: 第一个样 ...
- Codeforces Round #313 (Div. 2) D. Equivalent Strings
D. Equivalent Strings Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/ ...
- 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 ...
- Equivalent Strings (字符串相等?)
Equivalent Strings E - 暴力求解.DFS Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I ...
- Equivalent Strings
Equivalent Strings 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/E 题意: 给出 ...
- Codeforces Round #313 (Div. 1) B. Equivalent Strings
Equivalent Strings Problem's Link: http://codeforces.com/contest/559/problem/B Mean: 给定两个等长串s1,s2,判断 ...
- Codeforces 559B - Equivalent Strings
559B - Equivalent Strings 思路:字符串处理,分治 不要用substr(),会超时 AC代码: #include<bits/stdc++.h> #include&l ...
- Codeforces Round #313 D. Equivalent Strings(DFS)
D. Equivalent Strings time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 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 ...
- 【24.34%】【codeforces 560D】Equivalent Strings
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- AndroidStudio 各种异常情况处理大法
最近使用AndroidStudio出现了.java文件,显示为xml文件等问题,通过各种采坑之后,发现删除本地的缓存文件这个方法最管用,差不多可以根治95%的莫名其妙的问题.解决办法如下: 先将AS关 ...
- Linux离线安装Tomcat
系统环境: centos7.3.1611 openjdk version "1.8.0_102" apache-tomcat-9.0.36.tar.gz tomcat 安装 #链接 ...
- 什么是电商API
是电子商务平台提供给开发者和商家的一种技术接口,它允许第三方应用程序访问和操作平台的数据和服务.电商API的使用可以极大地提高业务效率,促进创新,并且为商家提供更多的商业机会. 以下是电商API的 ...
- Axure 0基础实战入门 模拟一个app页面
Axure 0基础实战入门 模拟一个app页面 第一次接触axure9,尝试模拟一个app页面与交互 页面原型 我选择了一个免费的日程app,下载rp文件后导入到axure 模拟实现登录页面 新建两个 ...
- 消毒 url 和 html (url encode and sanitizer html )
更新: 2020-06-24 FromRoute vs FromQuery decode FromRoute 是不会 auto decode 的, query string 就会 这个是微软默认的设置 ...
- Web核心
JavaWeb 技术栈
- redisson内存泄漏问题排查
问题描述 最近生产有个服务突然出现频繁告警,接口P99响应时间变长,运维同学观察到相应的pod cpu飙升,内存占用很高. cpu升高问题排查是老生常谈的话题了,一般可以使用top -p pid -H ...
- Go语言中的位运算符
位运算(bitwise operations)是计算机科学中非常基础且重要的运算类型,它直接操作二进制位.Go语言中提供了一组位运算符,用于执行位级别的操作. Go语言中的位运算符 按位与(& ...
- dotnet实现多态的三种方法
虚方法 virual 抽象方法 abstract 不能 new 不带方法体: 接口 Interface
- C++第六节课 引用变量 指针的升级版
#include <iostream> using namespace std; // C++的引用 是C指针的升级 可以提高代码的稳定性和健壮性 // const 修饰的引用 是 常引用 ...