zoukankan      html  css  js  c++  java
  • 「LibreOJ NOIP Round #1」537 DNA 序列

     

     字符串哈希

     1 #include <iostream>
     2 #include <map>
     3 #include <cstring>
     4 #include <cstdio>
     5 using namespace std;
     6 typedef unsigned long long ULL;
     7 map<ULL, int>Cnt;
     8 const int maxn = 5e6 + 7;
     9 ULL h[maxn], p[maxn];
    10 int base = 3;
    11 char s[maxn];
    12 int k;
    13 
    14 ULL get(int l, int r)
    15 {
    16     return h[r] - h[l - 1]*p[r - l + 1];
    17 }
    18 
    19 int main()
    20 {
    21     scanf("%s%d",s+1,&k);
    22 
    23     p[0] = 1;
    24     int len = strlen(s+1);
    25     for(int i = 1; i <= len; i++)
    26     {
    27         p[i] = p[i-1]*base;
    28         h[i] = h[i-1]*base + s[i];
    29         if(i >= k)
    30         {
    31             ULL tmp = get(i-k+1,i);
    32             Cnt[tmp]++;
    33         }
    34     }
    35     int ans = 0;
    36     for(map<ULL,int>::iterator it = Cnt.begin() ; it != Cnt.end() ; ++it) ans = max(ans,it->second);
    37     printf("%d
    ",ans);
    38     return 0;
    39 }
  • 相关阅读:
    事后诸葛亮
    OVS常用命令
    阿里云部署杂记
    Alpha冲刺总结
    测试随笔
    Alpha冲刺集合
    项目Alpha冲刺Day12
    项目Alpha冲刺Day11
    项目Alpha冲刺Day10
    MySQL修改密码
  • 原文地址:https://www.cnblogs.com/Edviv/p/11791834.html
Copyright © 2011-2022 走看看