7.12T1序列
1.序列
【问题描述】 Hzy 得到了一个字符串,这个字符串只有’A’,’G’,’C’,’T’这四种字符,她发现这个 序列中连续 k 个字符可以形成一种新的字符序列,她称这种序列为 Hzy 序列,她现在想知 道在所有的 Hzy 序列中,出现最多的一种的出现次数。
【输入格式】 输入文件名为 uaena.in。 输入文件的第一行为一个字符串,保证合法。 输入文件的第二行为一个正整数 k。
【输出格式】 输出文件名为 uaena.out。 输出文件只有一个数,即所求答案。
【输入输出样例 1】
input
AAAAA
1
output
5
【样例解释 1】 对于这段字符串中,连续的 k 个字符组成的 Hzy 序列只有 A,共出现 5 次,所以答案 为 5。
【输入输出样例 2】
ueana.in
ACTCACTC
4
ueana.out
2
【样例解释 1】 对于这段字符串中,连续的 k 个字符组成的 Hzy 序列有 ACTC,CTCA,TCAC,CACT 其中 ACTC 共出现 2 次,其余只出现了 1 次, 所以答案为 2。
【数据规模与规定】
n<=5 × 10^6 k<=10
sol: 哈希一下,O(n)水过
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
const ll Base=,Mod=;
int n,m,a[N];
char S[N];
inline int Check(char ch)
{
if(ch=='A') return ;
if(ch=='T') return ;
if(ch=='C') return ;
if(ch=='G') return ;
}
ll Seed[N];
inline void Pre(int n)
{
int i;
Seed[]=1ll; for(i=;i<=n;i++) Seed[i]=(ll)(Seed[i-]*%Mod);
}
struct Hash
{
ll Hash[N];
inline void Make(int n,int *a)
{
int i; Hash[]=; for(i=;i<=n;i++) Hash[i]=(Hash[i-]*%Mod+a[i])%Mod;
}
inline ll Ask(int l,int r)
{
return (ll)(Hash[r]+Mod-Hash[l-]*Seed[r-l+]%Mod)%Mod;
}
inline ll Get(int l,int r)
{
return Ask(l,r)*Seed[n-r]%Mod;
}
}Ha;
int Sum[];
int main()
{
freopen("ueana.in","r",stdin);
freopen("ueana.out","w",stdout);
int i,ans=;
scanf("%s",S+); n=strlen(S+); R(m);
for(i=;i<=n;i++) a[i]=Check(S[i]);
Pre(n); Ha.Make(n,a);
for(i=m;i<=n;i++)
{
// cout<<i-m+1<<' '<<i<<' '<<Ha.Ask(i-m+1,i)<<' '<<Ha.Get(i-m+1,i)<<endl;
Sum[Ha.Ask(i-m+,i)]++;
}
for(i=;i<=Seed[m];i++) ans=max(ans,Sum[i]);
Wl(ans);
return ;
}
/*
input
AAAAA
1
output
5 input
ACTCACTC
4
output
2
*/
7.12T1序列的更多相关文章
- 【夯实PHP基础】UML序列图总结
原文地址 序列图主要用于展示对象之间交互的顺序. 序列图将交互关系表示为一个二维图.纵向是时间轴,时间沿竖线向下延伸.横向轴代表了在协作中各独立对象的类元角色.类元角色用生命线表示.当对象存在时,角色 ...
- Windows10-UWP中设备序列显示不同XAML的三种方式[3]
阅读目录: 概述 DeviceFamily-Type文件夹 DeviceFamily-Type扩展 InitializeComponent重载 结论 概述 Windows10-UWP(Universa ...
- 软件工程里的UML序列图的概念和总结
俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习! 软件工程的一般开发过程:愿景分析.业务建模,需求分析,健壮性设计,关键设计,最终设计,实现…… 时序图也叫序列图(交互图),属于软件 ...
- python序列,字典备忘
初识python备忘: 序列:列表,字符串,元组len(d),d[id],del d[id],data in d函数:cmp(x,y),len(seq),list(seq)根据字符串创建列表,max( ...
- BZOJ 1251: 序列终结者 [splay]
1251: 序列终结者 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 3778 Solved: 1583[Submit][Status][Discu ...
- 最长不下降序列nlogn算法
显然n方算法在比赛中是没有什么用的(不会这么容易就过的),所以nlogn的算法尤为重要. 分析: 开2个数组,一个a记原数,f[k]表示长度为f的不下降子序列末尾元素的最小值,tot表示当前已知的最长 ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Repeated DNA Sequences 求重复的DNA序列
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
随机推荐
- HeidiSQL 导入Excel数据
一 前言 原文出处:http://blog.csdn.net/qq_27727681/article/details/53944744 二 效果演示: 2000多条数据,顺利导入成功. 三 实现方法 ...
- 实例详解jQuery的无new构建
jQuery的无new构建 jQuery框架的核心就是从HTML文档中匹配元素并对其执行操作. 回想一下使用 jQuery 的时候,实例化一个 jQuery 对象的方法: // 无 new 构造 $( ...
- cas sso 整合记录
首先说明下,我使用的cas-server版本是4.2.1 整合过程中遇到的问题及解决方式如下 1.因为使用https的话证书是个麻烦事,所以启用http 修改cas-server-webapp下的ca ...
- eventFlow 系列 <二> 领域事件
看一个聚合根: public class ExampleAggregate : AggregateRoot<ExampleAggregate, ExampleId>, IEmit<E ...
- tinymce富文本是在modal框中弹出显示的问题
记录一下,在用tinymce富文本的时候,由于是用在modal 上的,始终无法获取焦点,后来才发现问题出在tinymce在modal前创建了,所以导致这个问题,解决方案就是用 v-if="v ...
- vmware centos .net core sdk开发测试
环境:vmware + centos+ .net core2.0 一.安装.net core sdk sudo rpm -Uvh https://packages.microsoft.com/conf ...
- 充值css样式
@charset "utf-8"; /*reset CSS*/ body,ul,ol,dl,dd,h1,h2,h3,h4,h5,h6,figure,form,fieldset,le ...
- LLVM新建全局变量
在LLVM中,有原生的AST Clone,却没有一个比较好的Stmt copy功能,基于Scout在LLVM上进行的修改,我们实现了自己的Stmt Clone功能. 要进行Stmt Clone,肯定需 ...
- jmeter连接mysql数据库进行多条语句查询
前提工作: 1.在jmeter官网下载jmeter包(官网地址:https://jmeter.apache.org/).此外还需下载mysql驱动包,如:mysql-connector-java-5. ...
- Spring Cloud(二)服务提供者 Eureka + 服务消费者(rest + Ribbon)
Ribbon是什么? Ribbon是Netflix发布的开源项目,主要功能是提供客户端的软件负载均衡算法,将Netflix的中间层服务连接在一起.Ribbon客户端组件提供一系列完善的配置项如连接超时 ...