题面

题解

对字符串一脸懵的我肯定只能用$FFT$这种暴力方法水过啊。。。

将后面那个字符串翻转一下,对$\text{AGCT}$分别统计,用$FFT$就可以啦

代码

#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<algorithm>
#define RG register const int maxn(200010);
const double pi(acos(-1));
const char DNA[] = "AGCT";
struct complex { double x, y; } A[maxn], B[maxn];
inline complex operator + (const complex &lhs, const complex &rhs)
{ return (complex) {lhs.x + rhs.x, lhs.y + rhs.y}; }
inline complex operator - (const complex &lhs, const complex &rhs)
{ return (complex) {lhs.x - rhs.x, lhs.y - rhs.y}; }
inline complex operator * (const complex &lhs, const complex &rhs)
{
return (complex) {lhs.x * rhs.x - lhs.y * rhs.y,
lhs.y * rhs.x + lhs.x * rhs.y};
} char C[maxn], S[maxn];
int n, m, ans[maxn], N, r[maxn], P, T;
template<int opt> void FFT(complex *p)
{
for(RG int i = 1; i < N; i++) if(i < r[i]) std::swap(p[i], p[r[i]]);
for(RG int i = 1; i < N; i <<= 1)
{
complex rot = (complex) {cos(pi / i), opt * sin(pi / i)};
for(RG int j = 0; j < N; j += i << 1)
{
complex w = (complex) {1, 0};
for(RG int k = 0; k < i; ++k, w = w * rot)
{
complex x = p[j + k], y = w * p[i + j + k];
p[j + k] = x + y, p[i + j + k] = x - y;
}
}
}
} int main()
{
scanf("%d", &T);
while(T--)
{
scanf("%s%s", C, S);
n = strlen(C), m = strlen(S); std::reverse(S, S + m);
for(N = 1, P = 0; N < n + m; N <<= 1, ++P);
std::fill(ans, ans + n, 0);
for(RG int i = 1; i < N; i++)
r[i] = (r[i >> 1] >> 1) | ((i & 1) << (P - 1));
for(RG int p = 0; p < 4; ++p)
{
for(RG int i = 0; i < N; i++) A[i] = B[i] = (complex) {0, 0};
for(RG int i = 0; i < n; i++)
A[i] = (complex) {(C[i] == DNA[p]) ? 1. : 0., 0};
for(RG int i = 0; i < m; i++)
B[i] = (complex) {(S[i] == DNA[p]) ? 1. : 0., 0};
FFT<1>(A); FFT<1>(B);
for(RG int i = 0; i < N; i++) A[i] = A[i] * B[i];
FFT<-1>(A);
for(RG int i = m - 1; i < n; i++) ans[i] += (int) (A[i].x / N + .5);
}
int cnt = 0;
for(RG int i = m - 1; i < n; i++) if(ans[i] + 3 >= m) ++cnt;
printf("%d\n", cnt);
}
return 0;
}

最新文章

  1. Ubuntu 下,修改 Mac address
  2. 利用SoapUI 测试web service的方法介绍
  3. [团队项目] Scrum 项目 3.0 SCRUM 流程的步骤2: Spring 计划
  4. 【原】UIView实现点击着重效果的解决方案
  5. MySQL与SQL比较有那些区别呢
  6. delphi常用函数过程
  7. POJ 2013
  8. 【笨嘴拙舌WINDOWS】字符类型与字符串
  9. _vsnprintf 用法
  10. HDFS 的可靠性
  11. 修改Linux中的用户名
  12. arcgis api for silverlight使用google map等多个在线地图
  13. 通过Manifest的配置信息实现页面跳转,及总结
  14. mysql性能调优与架构设计笔记
  15. asp.net core系列 24 EF模型配置(主键,生成值,最大长度,并发标记)
  16. linux: 用户组, 文件权限详解
  17. Repeater数据控件的两个重要事件ItemDataBound 和 ItemCommand
  18. 2018.10.16 NOIP模拟 长者(主席树+hash)
  19. 可移植类库无法使用async、await关键字
  20. 七类网线 支持10gb/s的速度的计算方法

热门文章

  1. asp.net MVC4 框架揭秘 读书笔记系列1
  2. November 8th 2016 Week 46th Tuesday
  3. 内置函数 sorted
  4. Java基础加强之并发(四)synchronized关键字
  5. Day10 MVC
  6. Burpsuite-Intruder基础学习(一)
  7. 百度图表库ECharts
  8. 集合之fail-fast机制
  9. centos 6.8安装java环境
  10. nginx学习要点记录