hash

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
typedef unsigned long long ull;
ull xp[maxn],hash1[maxn];
 
void init()
{
    xp[0]=1;
    for (int i=1; i<=maxn; i++)
    {
        xp[i]=xp[i-1]*175;
    }
}
 
ull get_hash(int i,int l) //以i开始长度为l的字串
{
    return hash1[i]-hash1[i+l]*xp[l];
}
 
scanf("%s",str);
int len=strlen(str);
for (int i=len-1; i>=0; i--)
{
    hash1[i]=hash1[i+1]*175+str[i]-'a'+1;
}

  

posted @   Snow_in_winer  阅读(146)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何调试 malloc 的底层源码
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
阅读排行:
· Apifox不支持离线,Apipost可以!
· 历时 8 年,我冲上开源榜前 8 了!
· 零经验选手,Compose 一天开发一款小游戏!
· Trae 开发工具与使用技巧
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示