BZOJ 4259: 残缺的字符串 [FFT]
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]的更多相关文章
- BZOJ 4259 残缺的字符串 ——FFT
[题目分析] 同bzoj4503. 只是精度比较卡,需要试一试才能行O(∩_∩)O 用过long double,也加过0.4.最后发现判断的时候改成0.4就可以了 [代码] #include < ...
- BZOJ 4259 残缺的字符串(FFT)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4259 [题目大意] 给出两个包含*和小写字母的字符串,*为适配符,可以和任何字符匹配, ...
- 【BZOJ】4259: 残缺的字符串 FFT
[题意]给定长度为m的匹配串B和长度为n的模板串A,求B在A中出现多少次.字符串仅由小写字母和通配符" * "组成,其中通配符可以充当任意一个字符.n<=3*10^5. [算 ...
- 【刷题】BZOJ 4259 残缺的字符串
Description 很久很久以前,在你刚刚学习字符串匹配的时候,有两个仅包含小写字母的字符串A和B,其中A串长度为m,B串长度为n.可当你现在再次碰到这两个串时,这两个串已经老化了,每个串都有不同 ...
- BZOJ 4259: 残缺的字符串 FFT_多项式
Code: #include<bits/stdc++.h> #define maxn 1200000 using namespace std; void setIO(string s) { ...
- BZOJ 4259 残缺的字符串
思路 同样是FFT进行字符串匹配 只不过两个都有通配符 匹配函数再乘一个\(A_i\)即可 代码 #include <cstdio> #include <algorithm> ...
- luoguP4173 残缺的字符串 FFT
luoguP4173 残缺的字符串 FFT 链接 luogu 思路 和昨天做的题几乎一样. 匹配等价于(其实我更喜欢fft从0开始) \(\sum\limits_{i=0}^{m-1}(S[i+j]- ...
- Luogu P4173 残缺的字符串-FFT在字符串匹配中的应用
P4173 残缺的字符串 FFT在字符串匹配中的应用. 能解决大概这种问题: 给定长度为\(m\)的A串,长度为\(n\)的B串.问A串在B串中的匹配数 我们设一个函数(下标从\(0\)开始) \(C ...
- P4173 残缺的字符串(FFT字符串匹配)
P4173 残缺的字符串(FFT字符串匹配) P4173 解题思路: 经典套路将模式串翻转,将*设为0,设以目标串的x位置匹配结束的匹配函数为\(P(x)=\sum^{m-1}_{i=0}[A(m-1 ...
随机推荐
- Developing Skills
题目传送门:点击打开链接 #include <iostream> #include <cstdio> #include <cstdlib> #include < ...
- c语言基础学习09_关于复合类型的复习
=============================================================================struct A{ char array[10 ...
- java线程间通信:一个小Demo完全搞懂
版权声明:本文出自汪磊的博客,转载请务必注明出处. Java线程系列文章只是自己知识的总结梳理,都是最基础的玩意,已经掌握熟练的可以绕过. 一.从一个小Demo说起 上篇我们聊到了Java多线程的同步 ...
- django入门基础
首先要说的是django与其他的框架不同,django是一个封装的及其完善的框架,我们使用django也不会像之前写学生系统那样,django操作数据库使用自带的ORM来进行操作,Torando与Fl ...
- 【蓝桥杯单片机02】LED的基本控制
[蓝桥杯单片机02]LED的基本控制 广东职业技术学院 欧浩源 在CT107D单片机综合训练平台实现LED的基本控制和其他单片机开发平台不一样,不单单是控制几个LED实现跑马灯这么简单.因为在这个平 ...
- HTML 5 video 视频标签全属性详解
http://www.cnblogs.com/kiter/archive/2013/02/25/2932157.html 现在如果要在页面中使用video标签,需要考虑三种情况,支持Ogg Theor ...
- Phpstorm10 主题下载
================================================================================ submit:主题 http://ww ...
- Anaconda入门教程
Anaconda入门教程 [TOC] Anaconda是什么 Anaconda附带了 conda.Python 和 150 多个科学包及其依赖项.应用程序 conda 是包和环境管理器.Anacond ...
- IOS成长之路-用NSXMLParser实现XML解析
再次对xml进行解析,又有了些理解,如果有不对的地方,请给小弟指出,谢谢! <?xml version="1.0" encoding="UTF-8"?&g ...
- 史上最全的判断android,ios还是ipad访问,附上多种语言的实现方式
js判断: (function(a,b){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elain ...