B - Fuzzy Search (FFT)
题目链接:https://cn.vjudge.net/contest/281959#problem/B
题目大意:给你n,m,k。然后输入两个字符串,n代表第一个字符串s1,m代表第二个字符串s2,然后问你第二个字符串在第一个字符串能匹配的次数(选定第一个字符串的位置之后,任意s2中一个字符串,都能在s1对应的位置左右k个都能找到相同的字符)。
具体思路:和 这一篇的思路基本使用一样的。
FFT(Rock Paper Scissors Gym - 101667H)
AC代码:
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<stdio.h>
using namespace std;
# define ll long long
const double PI = acos(-1.0);
const int maxn = 8e5+;
struct complex
{
double r,i;
complex(double _r = ,double _i = )
{
r = _r;
i = _i;
}
complex operator +(const complex &b)
{
return complex(r+b.r,i+b.i);
}
complex operator -(const complex &b)
{
return complex(r-b.r,i-b.i);
}
complex operator *(const complex &b)
{
return complex(r*b.r-i*b.i,r*b.i+i*b.r);
}
};
void change(complex y[],int len)
{
int i,j,k;
for(i = , j = len/; i < len-; i++)
{
if(i < j)
swap(y[i],y[j]);
k = len/;
while( j >= k)
{
j -= k;
k /= ;
}
if(j < k)
j += k;
}
}
void fft(complex y[],int len,int on)
{
change(y,len);
for(int h = ; h <= len; h <<= )
{
complex wn(cos(-on**PI/h),sin(-on**PI/h));
for(int j = ; j < len; j += h)
{
complex w(,);
for(int k = j; k < j+h/; k++)
{
complex u = y[k];
complex t = w*y[k+h/];
y[k] = u+t;
y[k+h/] = u-t;
w = w*wn;
}
}
}
if(on == -)
for(int i = ; i < len; i++)
y[i].r /= len;
}
char str1[maxn],str2[maxn];
complex x1[maxn],x2[maxn];
int len1,len2,len=;
int vis[maxn][],id[maxn],cnt[];
ll ans[maxn];
int main()
{
int n,m,k;
scanf("%d %d %d",&n,&m,&k);
scanf("%s",str1+);
scanf("%s",str2+);
len1=strlen(str1+);
len2=strlen(str2+);
while(len<len1*||len<len2*)
len<<=;
// cout<<len<<endl;
int l=,r=;
id['A']=,id['G']=,id['T']=,id['C']=;
for(int i=; i<=n; i++)
{
while(l<n&&l<i-k)//判断这个区间内的字符。
cnt[id[(int)str1[l++]]]--;
while(r<n&&r<i+k)
cnt[id[(int)str1[++r]]]++;
for(int j=; j<=; j++)
if(cnt[j])
vis[i][j]=;
}
for(int i=; i<=; i++)
{
for(int j=; j<len; j++)
{
x1[j]=complex(,);
x2[j]=complex(,);
}
for(int j=; j<=n; j++)
{
if(vis[j][i])
x1[j-]=complex(,);
}
for(int j=; j<=m; j++)
{
if(id[(int)str2[j]]==i)
x2[m-j]=complex(,);
}
fft(x1,len,);
fft(x2,len,);
for(int j=; j<len; j++)
{
x1[j]=x1[j]*x2[j];
}
fft(x1,len,-);
for(int j=; j<len; j++)
{
ans[j]+=(ll)(x1[j].r+0.5);
}
}
int num=;
for(int i=; i<len; i++)
{
// cout<<i<<" "<<ans[i]<<endl;
if(ans[i]==m)
num++;
}
printf("%d\n",num);
return ;
}
B - Fuzzy Search (FFT)的更多相关文章
- 【CF528D】Fuzzy Search(FFT)
[CF528D]Fuzzy Search(FFT) 题面 给定两个只含有\(A,T,G,C\)的\(DNA\)序列 定义一个字符\(c\)可以被匹配为:它对齐的字符,在距离\(K\)以内,存在一个字符 ...
- Codeforces 528D Fuzzy Search(FFT)
题目 Source http://codeforces.com/problemset/problem/528/D Description Leonid works for a small and pr ...
- 2019.01.26 codeforces 528D. Fuzzy Search(fft)
传送门 fftfftfft好题. 题意简述:给两个字符串s,ts,ts,t,问ttt在sss中出现了几次,字符串只由A,T,C,GA,T,C,GA,T,C,G构成. 两个字符匹配的定义: 当si−k, ...
- 快速傅里叶(FFT)的快速深度思考
关于按时间抽取快速傅里叶(FFT)的快速理论深度思考 对于FFT基本理论参考维基百科或百度百科. 首先谈谈FFT的快速何来?大家都知道FFT是对DFT的改进变换而来,那么它究竟怎样改进,它改进的思想在 ...
- 【BZOJ3527】力(FFT)
[BZOJ3527]力(FFT) 题面 Description 给出n个数qi,给出Fj的定义如下: \[Fj=\sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_{ ...
- 【BZOJ4827】【HNOI2017】礼物(FFT)
[BZOJ4827][HNOI2017]礼物(FFT) 题面 Description 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每 ...
- FFT/NTT总结+洛谷P3803 【模板】多项式乘法(FFT)(FFT/NTT)
前言 众所周知,这两个东西都是用来算多项式乘法的. 对于这种常人思维难以理解的东西,就少些理解,多背板子吧! 因此只总结一下思路和代码,什么概念和推式子就靠巨佬们吧 推荐自为风月马前卒巨佬的概念和定理 ...
- 【BZOJ4503】两个串(FFT)
[BZOJ4503]两个串(FFT) 题面 给定串\(S\),以及带通配符的串\(T\),询问\(T\)在\(S\)中出现了几次.并且输出对应的位置. \(|S|,|T|<=10^5\),字符集 ...
- 【BZOJ4259】残缺的字符串(FFT)
[BZOJ4259]残缺的字符串(FFT) 题面 给定两个字符串\(|S|,|T|\),两个字符串中都带有通配符. 回答\(T\)在\(S\)中出现的次数. \(|T|,|S|<=300000\ ...
随机推荐
- AISing Programming Contest 2019 翻车记
A:签到. #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> ...
- C# 事件 订阅与发布
两种方式: 一: //服务器 public class Server { //服务器发布的事件 public event Action<string> MyEvent; public vo ...
- CUBA如何新增ServiceBean
简单的方法 在页面MIDDLEWARE模块,可以直接新建.编辑.删除 复杂的方法 在代码中手动实现,则需要1.添加Serviceweb-spring.xml中,添加 <entry key=&qu ...
- jasperReport和Ireport
<!-- groovy --> <dependency> <groupId>org.codehaus.groovy</groupId> <arti ...
- 【BZOJ1799】[AHOI2009]同类分布(动态规划)
[BZOJ1799][AHOI2009]同类分布(动态规划) 题面 BZOJ 洛谷 题解 很容易想到数位\(dp\),然而数字和整除原数似乎不好记录.没关系,直接枚举数字和就好了,这样子就可以把整除原 ...
- 读取2007以上版本的excel(xslx格式)
maven项目依赖jar包 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi ...
- Zookeeper客户端Curator---Getting Started
先说个小插曲,前几天有个网站转载我的文章没有署名作者,我有点不开心就给他们留言了,然后今天一看他们把文章删了.其实我的意思并不是你允许转载,我想表达的是我的付出需要被尊重.也不知道是谁的错~ ==== ...
- Qt shortcuts
ESC 切换到代码编辑模式 F1 查看帮助 F4 .h 与 .c or .cpp之间切换 shift + F2 声明与定义间切换 Ctrl + tab 切换已打开的文件 Ctrl + B 编 ...
- SQL Server 窗口函数详解:OVER()
语法 开窗函数支持分区.排序和框架三种元素,其语法格式如下: OVER ( [ <PARTITION BY clause> ] [ <ORDER BY clause> ] [ ...
- 盖得化工--selenium翻页测试
Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...