4259: 残缺的字符串

题意:s,t,星号任意字符,匹配方案数


和上题一样

多乘上一个\(a_{j+i}\)就行了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=(1<<20)+5;
const double PI=acos(-1);
inline int read(){
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
} struct meow{
double x, y;
meow(double a=0, double b=0):x(a), y(b){}
};
meow operator +(meow a, meow b) {return meow(a.x+b.x, a.y+b.y);}
meow operator -(meow a, meow b) {return meow(a.x-b.x, a.y-b.y);}
meow operator *(meow a, meow b) {return meow(a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x);}
meow conj(meow a) {return meow(a.x, -a.y);}
typedef meow cd; namespace FFT{
int n, rev[N];
void ini(int lim) {
n=1; int k=0;
while(n<lim) n<<=1, k++;
for(int i=0; i<n; i++) rev[i] = (rev[i>>1]>>1) | ((i&1)<<(k-1));
}
void dft(cd *a, int flag) {
for(int i=0; i<n; i++) if(i<rev[i]) swap(a[i], a[rev[i]]);
for(int l=2; l<=n; l<<=1) {
int m=l>>1;
cd wn = meow(cos(2*PI/l), flag*sin(2*PI/l));
for(cd *p=a; p!=a+n; p+=l) {
cd w(1, 0);
for(int k=0; k<m; k++) {
cd t = w*p[k+m];
p[k+m] = p[k] - t;
p[k] = p[k] + t;
w=w*wn;
}
}
}
if(flag==-1) for(int i=0; i<n; i++) a[i].x/=n;
}
}using FFT::dft; using FFT::ini; int n, m, lim;
cd a[N], b[N], a2[N], b2[N], a3[N], b3[N], c[N];
char s[N], t[N];
int ans, li[N];
int main() {
freopen("in","r",stdin);
m=read(); n=read(); lim=n+m-1; ini(lim);
scanf("%s%s",t,s);
for(int i=0; i<n; i++) s[i]= s[i]=='*' ? 0 : s[i]-'a'+1;
for(int i=0; i<m; i++) t[i]= t[i]=='*' ? 0 : t[i]-'a'+1; for(int i=0; i<n; i++) a[i].x = s[i], a2[i].x = 2*s[i]*s[i], a3[i].x = s[i]*s[i]*s[i];
for(int i=0; i<m; i++) b[m-1-i].x = t[i], b2[m-1-i].x = t[i]*t[i], b3[m-1-i].x = t[i]*t[i]*t[i]; dft(a, 1); dft(a2, 1); dft(a3, 1); dft(b, 1); dft(b2, 1); dft(b3, 1);
for(int i=0; i<FFT::n; i++) c[i] = a3[i]*b[i] - a2[i]*b2[i] + a[i]*b3[i];
dft(c, -1);
for(int i=0; i<=n-m; i++) if(floor(c[m-1+i].x+0.5)==0) li[++ans]=i;
printf("%d\n",ans);
for(int i=1; i<=ans; i++) printf("%d ",li[i]+1);
}

BZOJ 4259: 残缺的字符串 [FFT]的更多相关文章

  1. BZOJ 4259 残缺的字符串 ——FFT

    [题目分析] 同bzoj4503. 只是精度比较卡,需要试一试才能行O(∩_∩)O 用过long double,也加过0.4.最后发现判断的时候改成0.4就可以了 [代码] #include < ...

  2. BZOJ 4259 残缺的字符串(FFT)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4259 [题目大意] 给出两个包含*和小写字母的字符串,*为适配符,可以和任何字符匹配, ...

  3. 【BZOJ】4259: 残缺的字符串 FFT

    [题意]给定长度为m的匹配串B和长度为n的模板串A,求B在A中出现多少次.字符串仅由小写字母和通配符" * "组成,其中通配符可以充当任意一个字符.n<=3*10^5. [算 ...

  4. 【刷题】BZOJ 4259 残缺的字符串

    Description 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度为m,B串长度为n.可当你现在再次碰到这两个串时,这两个串已经老化了,每个串都有不同 ...

  5. BZOJ 4259: 残缺的字符串 FFT_多项式

    Code: #include<bits/stdc++.h> #define maxn 1200000 using namespace std; void setIO(string s) { ...

  6. BZOJ 4259 残缺的字符串

    思路 同样是FFT进行字符串匹配 只不过两个都有通配符 匹配函数再乘一个\(A_i\)即可 代码 #include <cstdio> #include <algorithm> ...

  7. luoguP4173 残缺的字符串 FFT

    luoguP4173 残缺的字符串 FFT 链接 luogu 思路 和昨天做的题几乎一样. 匹配等价于(其实我更喜欢fft从0开始) \(\sum\limits_{i=0}^{m-1}(S[i+j]- ...

  8. Luogu P4173 残缺的字符串-FFT在字符串匹配中的应用

    P4173 残缺的字符串 FFT在字符串匹配中的应用. 能解决大概这种问题: 给定长度为\(m\)的A串,长度为\(n\)的B串.问A串在B串中的匹配数 我们设一个函数(下标从\(0\)开始) \(C ...

  9. P4173 残缺的字符串(FFT字符串匹配)

    P4173 残缺的字符串(FFT字符串匹配) P4173 解题思路: 经典套路将模式串翻转,将*设为0,设以目标串的x位置匹配结束的匹配函数为\(P(x)=\sum^{m-1}_{i=0}[A(m-1 ...

随机推荐

  1. Codeforces780C

    题解:n个气球 从1到n染色,如果a.b和c是不同的正方形,a和b在它们之间有一条直接的路径,b和c之间有一条直接的路径,然后在这三个方块上的气球颜色是不同的. AC代码 #include <s ...

  2. Big Event in HDU(多重背包套用模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Java/Othe ...

  3. Linux下gdb的安装及使用入门

    1.安装gdb. 在root用户权限下: root@iZ2zeeailqvwws5dcuivdbZ:~# apt-get update ...... ...... ...... root@iZ2zee ...

  4. c语言基础学习07_关于指针的复习

    ============================================================================= 指针变量之间赋值是需要兼容的. 例如:int ...

  5. 如何在SecureCRT中给linux上传和下载文件 安装redis

    首先建立文件 /download sz和rz命令无法用.则用以下1.和2.3步骤   需要上传或者下载,需要使用rz和sz命令.如果linux上没有这两个命令工具,则需要先安装.可以使用yum安装.运 ...

  6. [国嵌攻略][157][SPI总线介绍]

    SPI总线架构 SPI(serial peripheral interface)串行外设接口,是一种高速,全双工,同步的通信总线.采用主从模式(master slave)架构,支持多个slave,一般 ...

  7. git回退操作

    情况一:checkout 当你修改了某个文件,未提交暂存区,回退本次修改 git checkout -- file 情况三:reset 当你的代码,已提交到暂存区,还未提交到远程仓库 git log ...

  8. 使用notepad++作为keil的外部编辑器

    之前一直不喜欢keil的编辑界面,但是又不想太浮夸.看到很多群里有人用vscode写stm32的序,但是直接用vscode编写的花,各种设置很麻烦.而且还不能调试.于是想到有没有一个轻便简约的外部编辑 ...

  9. log4j:ERROR Category option " 1 " not a decimal integer.错误解决

    log4j.properties 的配置文件中: log4j.appender.stdout.layout.ConversionPattern =  %d{ABSOLUTE} %5p %c{ 1 }: ...

  10. mybatis_SQL缓存(5)

    <settings> <!-- 这个配置使全局的映射器启用或禁用缓存 --> <setting name="cacheEnabled" value=& ...