码迷,mamicode.com
首页 > 其他好文 > 详细

DNA序列 LOJ NOIP模拟赛 D1T1 字符串哈希

时间:2017-11-05 22:23:24      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:stream   line   clu   序列   ios   nbsp   style   for   字符串   

字符串哈希

上代码

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
template<class T> inline void read(T &_a){
    bool f=0;int _ch=getchar();_a=0;
    while(_ch<0 || _ch>9){if(_ch==-)f=1;_ch=getchar();}
    while(_ch>=0 && _ch<=9){_a=(_a<<1)+(_a<<3)+_ch-0;_ch=getchar();}
    if(f)_a=-_a;
}

char str[5000001];
int k,n,ans,cnt[50000000],jc[11];
string tmp;

inline int getid(char s)
{
    if(s==A) return 1;
    if(s==G) return 2;
    if(s==C) return 3;
    return 4;
}

inline int h()
{
    int res=0;
    for (register int i=k-1;i>=0;--i)
        res+=getid(tmp[i])*jc[k-i];
    return res;
}

int main()
{
    jc[0]=1;
    for (register int i=1;i<=10;++i)
        jc[i]=jc[i-1]*5;
    scanf("%s",str+1);
    read(k);
    n=strlen(str+1);
    for (register int i=1;i+k<=n+1;++i)
    {
        tmp="";
        for (register int v=0;v<k;++v)
            tmp+=str[i+v];
        ans=max(ans,++cnt[h()]);
    }
    printf("%d",ans);
    return 0;
}

 

DNA序列 LOJ NOIP模拟赛 D1T1 字符串哈希

标签:stream   line   clu   序列   ios   nbsp   style   for   字符串   

原文地址:http://www.cnblogs.com/jaywang/p/7788937.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!