BZOJ 4259: 残缺的字符串 FFT_多项式
Description
Input
Output
#include<bits/stdc++.h>
#define maxn 1200000
using namespace std;
void setIO(string s)
{
string in=s+".in", out=s+".out";
freopen(in.c_str(),"r",stdin);
freopen(out.c_str(),"w",stdout);
}
#define pi 3.1415926535898
struct cpx
{
double x,y;
cpx(double a=0,double b=0){x=a,y=b;}
cpx operator+(const cpx b){ return cpx(x+b.x,y+b.y); }
cpx operator-(const cpx b){ return cpx(x-b.x,y-b.y); }
cpx operator*(const cpx b){ return cpx(x*b.x-y*b.y,x*b.y+y*b.x); }
}a1[maxn],a2[maxn],a3[maxn],b1[maxn],b2[maxn],b3[maxn];
void FFT(cpx *a,int n,int flag)
{
for(int i=0,k=0;i<n;++i)
{
if(i>k) swap(a[i],a[k]);
for(int j=n>>1;(k^=j)<j;j>>=1);
}
for(int mid=1;mid<n;mid<<=1)
{
cpx wn(cos(pi/mid), flag*sin(pi/mid)),x,y;
for(int j=0;j<n;j+=(mid<<1))
{
cpx w(1,0);
for(int k=0;k<mid;++k)
{
x=a[j+k],y=w*a[j+mid+k];
a[j+k]=x+y, a[j+k+mid]=x-y;
w=w*wn;
}
}
}
}
char str1[maxn],str2[maxn];
int n,m,len=1;
int arr[maxn],brr[maxn];
queue<int>Q;
int main()
{
// setIO("input");
scanf("%d%d%s%s",&n,&m,str1,str2);
while(len<n+m)len<<=1;
for(int i=0;i<n;++i) arr[n-1-i]=str1[i]=='*'?0.00:(double)str1[i]-'a'+1;
for(int i=0;i<m;++i) brr[i]=str2[i]=='*'?0.00:(double)str2[i]-'a'+1;
for(int i=0;i<n;++i) a1[i]=cpx(arr[i]*arr[i]*arr[i],0),a2[i]=cpx(arr[i],0), a3[i]=cpx(arr[i]*arr[i],0);
for(int i=0;i<m;++i) b1[i]=cpx(brr[i],0), b2[i]=cpx(brr[i]*brr[i]*brr[i],0), b3[i]=cpx(brr[i]*brr[i],0);
FFT(a1,len,1),FFT(a2,len,1),FFT(a3,len,1),FFT(b1,len,1),FFT(b2,len,1),FFT(b3,len,1);
for(int i=0;i<len;++i) a1[i]=a1[i]*b1[i]+a2[i]*b2[i]-a3[i]*b3[i]-a3[i]*b3[i];
FFT(a1,len,-1); for(int i=0;i+n-1<m;++i) if((int)(a1[i+n-1].x/len+0.1)==0) Q.push(i+1);
printf("%d\n",Q.size());
while(!Q.empty())
{
printf("%d ",Q.front());
Q.pop();
}
return 0;
}
BZOJ 4259: 残缺的字符串 FFT_多项式的更多相关文章
- BZOJ 4259: 残缺的字符串 [FFT]
4259: 残缺的字符串 题意:s,t,星号任意字符,匹配方案数 和上题一样 多乘上一个\(a_{j+i}\)就行了 #include <iostream> #include <cs ...
- 【刷题】BZOJ 4259 残缺的字符串
Description 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度为m,B串长度为n.可当你现在再次碰到这两个串时,这两个串已经老化了,每个串都有不同 ...
- BZOJ 4259 残缺的字符串(FFT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4259 [题目大意] 给出两个包含*和小写字母的字符串,*为适配符,可以和任何字符匹配, ...
- BZOJ 4259 残缺的字符串
思路 同样是FFT进行字符串匹配 只不过两个都有通配符 匹配函数再乘一个\(A_i\)即可 代码 #include <cstdio> #include <algorithm> ...
- BZOJ 4259 残缺的字符串 ——FFT
[题目分析] 同bzoj4503. 只是精度比较卡,需要试一试才能行O(∩_∩)O 用过long double,也加过0.4.最后发现判断的时候改成0.4就可以了 [代码] #include < ...
- 【BZOJ】4259: 残缺的字符串 FFT
[题意]给定长度为m的匹配串B和长度为n的模板串A,求B在A中出现多少次.字符串仅由小写字母和通配符" * "组成,其中通配符可以充当任意一个字符.n<=3*10^5. [算 ...
- bzoj 4259 4259: 残缺的字符串【FFT】
和bzoj 4503 https://www.cnblogs.com/lokiii/p/10032311.html 差不多,就是再乘上一个原串字符 有点卡常,先在点值下算最后一起IDFT #inclu ...
- 【BZOJ4259】残缺的字符串
[BZOJ4259]残缺的字符串 Description 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度为m,B串长度为n.可当你现在再次碰到这两个串时, ...
- 【BZOJ4259】残缺的字符串(FFT)
[BZOJ4259]残缺的字符串(FFT) 题面 给定两个字符串\(|S|,|T|\),两个字符串中都带有通配符. 回答\(T\)在\(S\)中出现的次数. \(|T|,|S|<=300000\ ...
随机推荐
- Servlet中使用RequestDispatcher调派请求--include
一共有两种调派方式,一个是include用于包含进来,一个是forward,是转发出去. 这时先测试包含的include方式. Some.java: package cc.openhome; impo ...
- hdu_1232_畅通工程_201403091018
畅通工程 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- Color the ball 线段树 区间更新但点查询
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...
- 网站配置https(腾讯云域名操作)
我们都知道http协议是超文本传输协议,早期的网站使用的都是http,但是并不安全,数据在传输过程中容易被拦截篡改.所以后面有了https,也就是经过ssl加密的http协议.本文主要对网站配置htt ...
- POJ 2960
也算是一道模板题吧,只需按照SG函数的定义求出每个值的SG,然后异或就可以了. #include <iostream> #include <cstdio> #include & ...
- 浅谈 System.Decimal 结构
引言 我们知道,Microsoft .NET Framework 中的 System.Decimal 结构(在 C# 语言中等价于 decimal keyword)用来表示十进制数,范围从 -(296 ...
- 学习笔记——DISTINCT
DISTINCT印象中向来被人诟病,说它效率低下.但网上那些SQL 面试题答案,却时有用之.其中 COUNT(DISTINCT 句式,我以前很少用,这里做个笔记. 为管理岗位业务培训信息,建立3个表: ...
- SQL2000数据库定期自动备份与修改
SQL2000数据库定期自动备份与修改 http://www.veryhuo.com 2009-11-19 烈火网 投递稿件 我有话说 在SQL server企业管理器中,可以设置数据库的定期自动 ...
- 离线安装 Rancher2.2.4 HA 集群
一.先决条件(所有主机执行) 1.1 基础设置 1.安装基础软件 yum install -y vim net-tools wget lrzsz 2.防火墙 sed -i 's/SELINUX=enf ...
- Elasticsearch 7.1.1 集群 + 配置身份验证
一.安装Elasticsearch 1.1 环境说明 Centos7.6 Elasticsearch7.1.1 #挂载数据盘 fdisk /dev/vdb n,p,,回车,回车,wq fdisk -l ...