[2016-03-23][codeforces][560][D][Equivalent Strings]

  • 时间:2016-03-23 14:15:39 星期三

  • 题目编号:[2016-03-23][codeforces][560][D][Equivalent Strings]

  • 题目大意:定义两个字符串相等方式,给出两个字符串,问是否相等

  • 分析:递归判断即可

  • 遇到的问题:长度为奇数的字符串一定不相等

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int issame(string str1,string str2){
  5. if(str1 == str2){
  6. return 1;
  7. }
  8. int m = str1.length();
  9. if(m & 1) return 0;
  10. return (issame(str1.substr(0,m/2),str2.substr(m/2,m/2))&&issame(str1.substr(m/2,m/2),str2.substr(0,m/2)))||
  11. (issame(str1.substr(0,m/2),str2.substr(0,m/2))&&issame(str1.substr(m/2,m/2),str2.substr(m/2,m/2)));
  12. }
  13. int main(){
  14. string str1,str2;
  15. cin>>str1>>str2;
  16. cout<<(issame(str1,str2)?"YES":"NO")<<‘\n‘;
  17. return 0;
  18. }

来自为知笔记(Wiz)

时间: 2024-10-14 14:45:13

[2016-03-23][codeforces][560][D][Equivalent Strings]的相关文章

D. Equivalent Strings

D. Equivalent Strings 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <string> 7 #include <vector> 8 #include <set> 9 #include <map>

分布式技术一周技术动态 2016.03.20

分布式系统实践 1. 基于Mesos和Docker的分布式计算平台 https://mp.weixin.qq.com/s?__biz=MzAxMDgzOTA2Mw==&mid=402769128&idx=1&sn=cea3ad1357bd9312acf1768c0a493bfd&scene=1&srcid=0318BTuxT0fsFYwPjpeyuDOa&key=710a5d99946419d90fbc1e7600cce055b6e997d6afafc74c

codeforces 560 C Gerald&#39;s Hexagon

神精度--------这都能过,随便算就好了,根本不用担心 就是把六边形补全成三角形,然后去掉补的三个三角形,然后面积除以边长1的三角形的面积即可.... #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector&

Codeforces 360C Levko and Strings dp

题目链接:点击打开链接 题意: 给定长度为n的字符串s,常数k 显然s的子串一共有 n(n-1)/2 个 要求找到一个长度为n的字符串t,使得t对应位置的k个子串字典序>s #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<vector> #include<set> using namespace std; #

Codeforces 385B Bear and Strings

题目链接:Codeforces 385B Bear and Strings 记录下每一个bear的起始位置和终止位置,然后扫一遍记录下来的结构体数组,过程中用一个变量记录上一个扫过的位置,用来去重. #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int MAX_N = 5000 + 100; char str[MAX_N]; struct Node

Codeforces 482C Game with Strings(dp+概率)

题目链接:Codeforces 482C Game with Strings 题目大意:给定N个字符串,现在从中选定一个字符串为答案串,你不知道答案串是哪个,但是可以通过询问来确定, 每次询问一个位置上字符为多少.现在你询问的每个位置的概率是相同的,(问过的位置不会再问),求询问次数的期 望. 解题思路:因为字符串长度不会大于20,所以用二进制表示询问了哪些位置,C[s]即为询问s的位置可以确定多少个字 符串.这步不能通过枚举s,然后判断处理,复杂度为o(2^20 * 20 * 50),太高.可

Equivalent Strings (字符串相等?)

Equivalent Strings E - 暴力求解.DFS Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are

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

Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases: They are equal. If we split string a into two halves of the same size a1 and a2

Codeforces Round #313 (Div. 2) D. Equivalent Strings 解题心得

原题: Description Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases: They are equal. If we split string a into two halves of the sam