针对字符串hash 我早就听闻可以暴力的干一些事情。

比如 可以...

很多很多 实现O(n)求出 模式串在文本串出现的次数。

但是我不会这什么hash。

我会自然溢出字符串hash 嘿嘿 unsigned long long 溢出后可以 对2^32自动取%

采用p进制字符串hash 我想出现冲突的可能性是 99%

这道题呢 采用map 可以快速A但是hash 也是可以取得不错的效果的。

我想 可以随便搞了。sort稳重操作!

//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<utility>
#include<set>
#include<bitset>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<vector>
#include<ctime>
#define INF 168430090
#define mod 19260817
#define ull unsigned long long
using namespace std;
char buf[<<],*fs,*ft;
inline char getc()
{
return (fs==ft&&(ft=(fs=buf)+fread(buf,,<<,stdin),fs==ft))?:*fs++;
}
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void put(int x)
{
x<?putchar('-'),x=-x:;
int num=;char ch[];
while(x)ch[++num]=x%+'',x/=;
num==?putchar(''):;
while(num)putchar(ch[num--]);
putchar('\n');return;
}
const int MAXN=,maxn=;
int n,ans,c[maxn];
char a[MAXN];
struct wy
{
ull b;
int id;
friend int operator <(const wy &x,const wy &y)
{
if(x.b==y.b)return x.id<y.id;
return x.b<y.b;
}
}t[maxn];
int main()
{
//freopen("1.in","r",stdin);
n=read();
for(int i=;i<=n;i++)
{
scanf("%s",a+);
int len=strlen(a+);
t[i].id=i;
for(int j=;j<=len;j++)t[i].b=t[i].b*mod+a[j];
}
sort(t+,t++n);
for(int i=;i<=n;i++)if(t[i].b==t[i-].b)c[t[i].id]=;
for(int i=;i<=n;i++)if(c[i]==)put(i);
return ;
}

我居北海君南海,寄雁传书谢不能。

请教神牛_字符串hash的更多相关文章

  1. 【字符串算法1】 再谈字符串Hash(优雅的暴力)

    [字符串算法1] 字符串Hash(优雅的暴力) [字符串算法2]Manacher算法 [字符串算法3]KMP算法 这里将讲述  [字符串算法1] 字符串Hash 老版原文: RK哈希(Rabin_Ka ...

  2. 字符串Hash相关

    其实也并不是什么特别难的算法,但是我个人实在是不太喜欢字符串之类的东西(字符串神马的真的是麻烦),于是一直拖着不想看,然后模板题之类的也懒得做. Hash的思想其实也没什么复杂的,就是给定一系列字符串 ...

  3. [CQOI2014][bzoj3507] 通配符匹配 [字符串hash+dp]

    题面 传送门 思路 0x01 KMP 一个非常显然而优秀的想法:把模板串按照'*'分段,然后对于每一段求$next$,'?'就当成可以对于任意字符匹配就行了 对于每个文本串,从前往后找第一个可以匹配的 ...

  4. Clairewd's message /// 字符串hash

    题目大意: 给定字符串s 是26个字母对应的密文字母 给定字符串c1 是 密文+部分原文 原文可能缺损 要求将原文补全输出 利用s得到密文字母对应的原字母rs 利用rs翻译c1得到 原文+部分密文c2 ...

  5. P7114 [NOIP2020] 字符串匹配 (字符串hash+树状数组)

    好多题解用的扩展KMP(没学过,所以不用这种方法). 我们按照题目要求记F(s)表示s串的权值,可以预处理出前缀权值(用于A)和后缀权值(用于C),枚举AB的长度i=2~n-1,不需要分开枚举,我们只 ...

  6. [知识点]字符串Hash

    1.前言 字符串的几大主要算法都多少提及过,现在来讲讲一个称不上什么算法, 但是非常常用的东西——字符串Hash. 2.Hash的概念 Hash更详细的概念不多说了,它的作用在于能够对复杂的状态进行简 ...

  7. 【BZOJ-3555】企鹅QQ 字符串Hash

    3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1545  Solved: 593[Submit][Statu ...

  8. C Primer Plus_第四章_字符串和格式化输入输出_编程练习

    Practice 1.输入名字和姓氏,以"名字,姓氏"的格式输出打印. #include int main(void) { char name[20]; char family[2 ...

  9. POJ 1200 字符串HASH

    题目链接:http://poj.org/problem?id=1200 题意:给定一个字符串,字符串只有NC个不同的字符,问这个字符串所有长度为N的子串有多少个不相同. 思路:字符串HASH,因为只有 ...

随机推荐

  1. github贡献开源项目

    1.正常流程 1.拷贝项目到自己的github 2.本地修改后提交远程仓库 3.创建讨论Pull requests 4.开源项目者合并到master分支 5.删除仓库 2.快速发出讨论Pull req ...

  2. 【被C折腾系列】用C调DIOCP编码客户端通信

    前几天有个朋友,说他们公司做手游,服务端用的DIOCP3里面做文件服务器,客户端用cocos-x,在调试与diocp通信时老是失败! 于是,我下载了一个Codeblocks经过几个小时的折腾,终于折腾 ...

  3. 【Java】加载驱动方法

    1.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 2. DriverManager.register ...

  4. YII页面显示trace

    修改protected/config/main.php 'db'=>array( 'connectionString' => 'mysql:host=localhost;dbname=te ...

  5. 【emWin】例程十二:FontCvt生成字库

    介绍: 本例程介绍使用官方字库生成软件FontCvt5.22生成字库文件,并在液晶上显示文字. 实验指导书及代码包下载: 链接:http://pan.baidu.com/s/1eSkliDW 密码:o ...

  6. Java知多少(15)字符串

    从表面上看,字符串就是双引号之间的数据,例如“微学苑”.“http://www.weixueyuan.net”等.在Java中,可以使用下面的方法定义字符串:    String stringName ...

  7. WPF Input Validation Using MVVM

    Data validation is a key part in WPF.Validation is used to alert the user that the data he entered i ...

  8. How do I convert an enum to a list in C#?

    How do I convert an enum to a list in C#? This will return an IEnumerable<SomeEnum> of all the ...

  9. How to set asp.net Identity cookies expires time

    If IsPersistent property of AuthenticationProperties is set to false, then the cookie expiration tim ...

  10. django 单元测试错误总结

    TestCase django自带有一个TestCase模块来进行测试,我们可以参考官网 来写单元测试的代码.我这里主要是总结一些错误. 用户无法登陆 我们有些api登录后才可以进行测试,所以我们可以 ...