Codeforces Round #313 (Div. 2) D Equivalent Strings(dfs)
来源:互联网 发布:研究生做软件测试待遇 编辑:程序博客网 时间:2024/05/19 12:18
这道题先用了笨办法,就是用中间数组复制字符串,再比较,这样不仅浪费时间,而且最后做了半天还wa了,爆栈了Orz。想一个好的方法确实是事半功倍啊~~
#include<bits/stdc++.h>using namespace std;const int maxn = 2e5+5;char a[maxn],b[maxn];int dfs(int al,int ar,int bl,int br) { int flag = 1; for(int i = al,j = bl;i <= ar;i++,j++) { if(a[i-1] != b[j-1]) { flag = 0; break; } } if(flag) return 1; int len = ar - al +1; if(len % 2 != 0) return 0; int mid = len >> 1; if(dfs(al,al+mid-1,bl,bl+mid-1) && dfs(al+mid,ar,bl+mid,br)) return 1; else if(dfs(al,al+mid-1,bl+mid,br) && dfs(al+mid,ar,bl,bl+mid-1)) return 1; else return 0;}int main() { scanf("%s%s",a,b); int len = strlen(a); if(dfs(1,len,1,len)) puts("YES"); else puts("NO");}
这个代码就清晰明了了。
0 0
- Codeforces Round #313 (Div. 2) D Equivalent Strings(dfs)
- Codeforces Round #313 (Div. 2)D. Equivalent Strings(字符串)
- Codeforces Round #313 D. Equivalent Strings(DFS)
- Codeforces Round #313 (Div. 2) D. Equivalent Strings 字符串处理
- Codeforces Round #313 (Div. 2) D Equivalent Strings
- Codeforces Round #313 (Div. 2) Problem D - Equivalent Strings
- Equivalent Strings(Codeforces Round #313 (Div. 2) D)
- Codeforces Round #313 (Div. 2) 560D Equivalent Strings(dos)
- Codeforces Round #313 (Div. 2)560D. Equivalent Strings
- Codeforces Round #313 (Div. 2) D. Equivalent Strings(简单搜索)
- Codeforces Round #313 (Div. 1) B. Equivalent Strings DFS暴力
- CodeForces - 560D Equivalent Strings (DFS)
- Round #313 (Div. 2) D. Equivalent Strings-大水题递归
- Codeforces Round #313 (Div. 2) Equivalent Strings(搜索)
- 规律+DFS Codeforces Round div2 D. Equivalent Strings
- Codeforces Round #313 Equivalent Strings(递归)
- Codeforces Round #313 (Div. 1) B. Equivalent Strings
- codeforces Round 313 (Div. 1) B.Equivalent Strings
- js中的继承
- 虚拟机上的centos输入ifconfig却没有本机IP地址
- ionic实现表格头部和第一列固定且都可滚动
- JDK自带工具keytool生成ssl证书
- Retrofit和RxJava结合使用
- Codeforces Round #313 (Div. 2) D Equivalent Strings(dfs)
- Git 的origin和master分析
- 死锁问题的解决
- https封装工具类
- cordova开发自定义插件
- hadoop安装(一)
- Spring简单入门
- 【STM32】keil环境下移植cJSON
- maven利用Profile构建不同环境的部署包