hdu5782
来源:互联网 发布:c语言中最大公约数 编辑:程序博客网 时间:2024/05/17 18:43
给定两个长度相等的字符串
问他们的第 i个前缀是否循环相等
循环相等的定义是,两个长度相等的字符串
问他们的第 i个前缀是否循环相等
循环相等的定义是,两个长度相等的字符串
其中一个字符串能通过循环移位得到另一个
Bp[i][j]表示以B串中1~i为子串,和A中以j开头的子串是否匹配
#include <bitset>using namespace std;typedef pair<int,int> Pii;typedef long long LL;typedef unsigned long long ULL;typedef double DBL;typedef long double LDBL;#define MST(a,b) memset(a,b,sizeof(a))#define CLR(a) MST(a,0)#define SQR(a) ((a)*(a))#define PCUT puts("\n----------")const int maxn=1e4+10;//const int maxn=10;char A[maxn], B[maxn];bitset<maxn> posA[26], posB[26], Ap[maxn], Bp[maxn], ans, tem, pre[maxn];int main(){ #ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout); #endif for(int i=1; i<maxn; i++) pre[i] = pre[i-1].set(i-1); while(~scanf(" %s %s", A, B)) { int N=strlen(A); for(int i=0; i<26; i++) posA[i].reset(), posB[i].reset(); for(int i=0; i<N; i++) { posA[A[i]-'a'][i] = 1; posB[B[i]-'a'][i] = 1; } Ap[0] = posB[A[0]-'a']; Bp[0] = posA[B[0]-'a']; for(int i=1; i<N; i++) Bp[i] = Bp[i-1] & (posA[B[i]-'a']>>i); ans.reset(); tem.reset(); bool all = A[0]==B[0]; if(all) ans[0]=1; for(int i=1; i<N; i++) { Ap[i] = Ap[i-1] & (posB[A[i]-'a']>>i); int l=0, r=N-1; while(l<r) { int mid=(l+r+1)>>1; if(!Bp[mid][i]) r=mid-1; else l=mid; } all &= A[i]==B[i]; if(all) ans[i]=1; if(l==0 && A[i] != B[0]) continue; ans |= (Ap[i-1]&pre[l+1]) << (i-1); } for(int i=0; i<N; i++) putchar(ans[i]+'0'); puts(""); } return 0;}
0 0
- hdu5782
- 【bitset】hdu5782
- HDU5782(结论题hash+字符串同构)
- hdu5782 Cycle(后缀数组+bitset)(16多校赛5)
- 2016多校联合训练赛 第五场1002 Cycle hdu5782
- 我的第一个shell脚本文件
- 二叉搜索树的第k个结点
- mysql 1449 : The user specified as a definer ('root'@'%') does not exist 解决方法
- 数据流中的中位数
- EA&UML日拱一卒--序列图(Sequence Diagram)::同步/异步
- hdu5782
- 滑动窗口的最大值
- ViewPager使用版本一
- Java_RandomAccessFile和IO流
- Easy-14
- 矩阵中的路径
- 1.docker的安装
- 机器人的运动范围
- POJ2245Lotto