首页 > 其他 > 详细

codeforces #313 div1 B

时间:2016-04-09 16:57:44      阅读:214      评论:0      收藏:0      [点我收藏+]

模拟判定就可以了

判定字符串是否相等用hash来判断

QAQ 值得一提的是一开始我交的时候T了

结果我将递归的顺序调整了一下就A了

(并不知道为什么

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;

typedef unsigned long long LL;
const int maxn=200010;
const int x=13331;
int n;
char s[maxn];
char p[maxn];
LL xp[maxn],hs[maxn],hp[maxn];

bool cmp(int a,int b,int c,int d){
	return hs[a]-hs[b+1]*xp[b-a+1]==hp[c]-hp[d+1]*xp[d-c+1];
}
bool Solve(int a,int b,int c,int d){
	if(cmp(a,b,c,d))return true;
	if((b-a+1)&1)return false;
	int e=(a+b)>>1;
	int f=(c+d)>>1;
	if(Solve(a,e,f+1,d)&&Solve(e+1,b,c,f))return true;
	if(Solve(a,e,c,f)&&Solve(e+1,b,f+1,d))return true;
	return false;
}

int main(){
	scanf("%s",s+1);scanf("%s",p+1);
	n=strlen(s+1);
	xp[0]=1;
	for(int i=1;i<=n;++i)xp[i]=xp[i-1]*x;
	hs[n+1]=0;hp[n+1]=0;
	for(int i=n;i>=1;--i){
		hs[i]=hs[i+1]*x+s[i]-‘a‘;
		hp[i]=hp[i+1]*x+p[i]-‘a‘;
	}
	if(Solve(1,n,1,n))printf("YES\n");
	else printf("NO\n");
	return 0;
}

  

codeforces #313 div1 B

原文:http://www.cnblogs.com/joyouth/p/5371895.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!