zoukankan      html  css  js  c++  java
  • codeforces #313 div1 B

    模拟判定就可以了

    判定字符串是否相等用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
    ");
    	else printf("NO
    ");
    	return 0;
    }
    

      

  • 相关阅读:
    4.28综合练习
    团队项目第一阶段冲刺第六天
    4.27防盗链和代理
    梦断代码阅读笔记3
    团队项目第一阶段冲刺第五天
    4.26抓取猪⼋戒数据
    团队项目第一阶段冲刺第四天
    4.25xpath解析
    4.24aiohttp模块学习
    如何将类数组转化为数组?
  • 原文地址:https://www.cnblogs.com/joyouth/p/5371895.html
Copyright © 2011-2022 走看看