there

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
int n, m, aa[300005], bb[300005], lim=1, tmpcnt, rev[1100005];
const double PI=acos(-1.0);
char ss[300005];
vector<int> vec;
struct Complex{
double x, y;
Complex(double xx=0.0, double yy=0.0){
x = xx;
y = yy;
}
Complex operator+(const Complex &u)const{
return Complex(x+u.x, y+u.y);
}
Complex operator-(const Complex &u)const{
return Complex(x-u.x, y-u.y);
}
Complex operator*(const Complex &u)const{
return Complex(x*u.x-y*u.y, x*u.y+y*u.x);
}
Complex operator*(double u)const{
return Complex(x*u, y*u);
}
}a[1100005], b[1100005], c[1100005];
void fft(Complex a[], int opt){
for(int i=0; i<lim; i++)
if(i<rev[i])
swap(a[i], a[rev[i]]);
for(int i=2; i<=lim; i<<=1){
int tmp=i>>1;
Complex wn=Complex(cos(PI*2.0/i), opt*sin(PI*2.0/i));
for(int j=0; j<lim; j+=i){
Complex w=Complex(1.0, 0.0);
for(int k=0; k<tmp; k++){
Complex tmp1=a[j+k], tmp2=w*a[j+k+tmp];
a[j+k] = tmp1 + tmp2;
a[j+k+tmp] = tmp1 - tmp2;
w = w * wn;
}
}
}
if(opt==-1)
for(int i=0; i<lim; i++)
a[i].x /= lim;
}
int main(){
cin>>m>>n;
while(lim<=n+m) lim <<= 1, tmpcnt++;
for(int i=0; i<lim; i++)
rev[i] = (rev[i>>1]>>1) | ((i&1)<<(tmpcnt-1));
scanf("%s", ss);
for(int i=0; i<m; i++)
if(ss[i]!='*')
aa[i] = ss[i] - 'a' + 1;
scanf("%s", ss);
for(int i=0; i<n; i++)
if(ss[i]!='*')
bb[i] = ss[i] - 'a' + 1;
reverse(aa, aa+m);
for(int i=0; i<m; i++)
a[i] = Complex(aa[i]*aa[i]*aa[i], 0.0);
for(int i=0; i<n; i++)
b[i] = Complex(bb[i], 0.0);
fft(a, 1);
fft(b, 1);
for(int i=0; i<lim; i++)
c[i] = a[i] * b[i];
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for(int i=0; i<m; i++)
a[i] = Complex(aa[i]*aa[i], 0.0);
for(int i=0; i<n; i++)
b[i] = Complex(bb[i]*bb[i], 0.0);
fft(a, 1);
fft(b, 1);
for(int i=0; i<lim; i++)
c[i] = c[i] - a[i] * b[i] * 2.0;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for(int i=0; i<m; i++)
a[i] = Complex(aa[i], 0.0);
for(int i=0; i<n; i++)
b[i] = Complex(bb[i]*bb[i]*bb[i], 0.0);
fft(a, 1);
fft(b, 1);
for(int i=0; i<lim; i++)
c[i] = c[i] + a[i] * b[i];
fft(c, -1);
for(int i=m-1; i<n; i++)
if(fabs(c[i].x)<1e-6)
vec.push_back(i-m+2);
cout<<vec.size()<<endl;
for(int i=0; i<vec.size(); i++)
printf("%d ", vec[i]);
printf("\n");
return 0;
}

luogu4173 残缺的字符串的更多相关文章

  1. Luogu4173 残缺的字符串 FFT

    传送门 考虑如何使用FFT计算两个子串是否匹配.如果字符集比较小可以把每个字符都拿出来暴力做一遍,但是字符集比较大的时候复杂度就会有问题.这个时候可以考虑匹配函数. 先考虑没有通配符的情况.将\(A\ ...

  2. BZOJ 4259: 残缺的字符串 [FFT]

    4259: 残缺的字符串 题意:s,t,星号任意字符,匹配方案数 和上题一样 多乘上一个\(a_{j+i}\)就行了 #include <iostream> #include <cs ...

  3. 【BZOJ4259】残缺的字符串

    [BZOJ4259]残缺的字符串 Description 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度为m,B串长度为n.可当你现在再次碰到这两个串时, ...

  4. 【BZOJ4259】残缺的字符串(FFT)

    [BZOJ4259]残缺的字符串(FFT) 题面 给定两个字符串\(|S|,|T|\),两个字符串中都带有通配符. 回答\(T\)在\(S\)中出现的次数. \(|T|,|S|<=300000\ ...

  5. 【BZOJ4259】残缺的字符串 FFT

    [BZOJ4259]残缺的字符串 Description 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度为m,B串长度为n.可当你现在再次碰到这两个串时, ...

  6. CF528D Fuzzy Search 和 BZOJ4259 残缺的字符串

    Fuzzy Search 给你文本串 S 和模式串 T,求 S 的每个位置是否能模糊匹配上 T. 这里的模糊匹配指的是把 T 放到 S 相应位置上之后,T 中每个字符所在位置附近 k 个之内的位置上的 ...

  7. luoguP4173 残缺的字符串 FFT

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

  8. 洛谷 P4173 残缺的字符串 (FFT)

    题目链接:P4173 残缺的字符串 题意 给定长度为 \(m\) 的模式串和长度为 \(n\) 的目标串,两个串都带有通配符,求所有匹配的位置. 思路 FFT 带有通配符的字符串匹配问题. 设模式串为 ...

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

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

随机推荐

  1. vue2.0:(九)、外卖App弹窗部分星星评分

    本篇是星星评分部分,先上代码: 1.header.vue: <template> <transition name="fade">            & ...

  2. vue2.0:(八-2)、外卖App弹窗部分sticky footer

    什么是sticky-footer ? 如果页面内容不够长的时候,页脚块粘贴在视窗底部,如果内容足够长时,页脚块会被内容向下推送.那具体要怎么做呢?下面以外卖App为例: 第一种方法:这个自己用过,是好 ...

  3. android 跨进程通讯 AIDL

    跨进程如何通讯?两个进程无法直接通讯,通过Android系统底层间接通讯.基于service的aidl实现跨进程通讯. 什么叫AIDL? Android interface definition la ...

  4. apple-touch-icon-precomposed

    <link rel="apple-touch-icon-precomposed" href=""> apple-touch-icon-precomp ...

  5. 大家一起和snailren学java-(一)对象导论

    OOP,是java语言的特性.面向对象思想贯穿整个java开发. 那什么是面向对象呢?什么是对象? 在面向对象设计语言看来,万事万物都为对象.生活中的一个物体,有自己的属性,有自己的活动.比如一辆汽车 ...

  6. 【虚拟机-远程连接】Azure Linux 虚拟机常见导致无法远程的操作

    对Azure虚拟机的一些操作可能会导致无法远程连接,本文罗列了以下导致不能远程连接的场景: 场景1 - 在虚拟机配置IP地址或MAC地址 场景2 - 错误地修改服务的配置文件 场景3 - 误设置防火墙 ...

  7. jsp之获传统方式取后台数据

    1.建立模型对象: package com.java.model; public class Student { private String name; private int age; publi ...

  8. MovieReview—Ghost in the Shell(攻壳机动队:笑脸男事件,个别的11人事件)

    AI with Wisdom         I have recently watched two films in the series of Ghost in the Shell, Smilin ...

  9. MySql查询时间段的方法

    本文实例讲述了MySql查询时间段的方法.分享给大家供大家参考.具体方法如下: MySql查询时间段的方法未必人人都会,下面为您介绍两种MySql查询时间段的方法,供大家参考. MySql的时间字段有 ...

  10. JS实用技术

    JS外部引用其他文件(建议) <script src="myScript1.js"></script> JS输出显示方式 使用 window.alert() ...