题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3555

很久以前就讲过哈希,但一直没写过题,所以这是哈希第一题!

哈希就是把一个字符串映射成一个数,竟然还能排序!

参考了 hzwer 的博客,但为什么写出来比别人慢了一倍...

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int const maxn=,maxm=;
int n,m,tp,ans;
ll f[maxn][maxm],g[maxn][maxm],tmp[maxn];//ll
char ch[maxm];
void init(int x)
{
for(int i=;i<=m;i++)f[x][i]=f[x][i-]*+ch[i];
for(int i=m;i;i--)g[x][i]=g[x][i+]*+ch[i];
}
int main()
{
scanf("%d%d%d",&n,&m,&tp);
for(int i=;i<=n;i++){cin>>ch+; init(i);}
for(int j=;j<=m;j++)//枚举每一位
{
for(int i=;i<=n;i++)//除这一位的每一个字符串
tmp[i]=f[i][j-]*+g[i][j+]*;
sort(tmp+,tmp+n+);
for(int i=,nw=;i<=n;i++)
{
if(tmp[i]==tmp[i-])ans+=nw,nw++;
else nw=;
}
}
printf("%d\n",ans);
return ;
}

bzoj3555 [Ctsc2014]企鹅QQ——字符串哈希的更多相关文章

  1. BZOJ 3555: [Ctsc2014]企鹅QQ [字符串哈希]【学习笔记】

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

  2. Luogu P4503 [CTSC2014]企鹅QQ(字符串哈希)

    P4503 [CTSC2014]企鹅QQ 题面 题目背景 \(PenguinQQ\) 是中国最大.最具影响力的 \(SNS(Social Networking Services)\) 网站,以实名制为 ...

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

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

  4. bzoj3555: [Ctsc2014]企鹅QQ

    将字符串hash.不难写.然而1.注意用longlong2.数组大小注意...3.似乎别人都用的unsigned long long ?. #include<cstdio> #includ ...

  5. 【字符串哈希】bzoj3555 [Ctsc2014]企鹅QQ

    枚举每个位置,给每个串的前半部分一个哈希值,后半部分一个哈希值,若是它们均相等,则视为这两个串相似. 每次转移之后,排序一下就行了. O(L*n*log(n)). #include<cstdio ...

  6. 【bzoj3555】[Ctsc2014]企鹅QQ 简单哈希

    传送门 题目分析 题意即求有多少对字符串只相差一个字符,枚举删除每个字符后的哈希, 看有多少相等即可. 比如有如下字符串:$Sd123$,其中S部分的哈希值为H,删除的是d,则原字符串的哈希值为$$( ...

  7. 【题解】 bzoj3555: [Ctsc2014]企鹅QQ (字符串Hash)

    题面戳我 Solution 我们分析题意,他要求的是两个字符串只有一个字符不同,然后我们再看长度\(L \leq 200\),显然我们就可以把每一位删除后\(Hash\),然后判断相同个数即可 我一开 ...

  8. 【bzoj3555】[Ctsc2014]企鹅QQ 字符串hash

    题目描述 PenguinQQ是中国最大.最具影响力的SNS(Social Networking Services)网站,以实名制为基础,为用户提供日志.群.即时通讯.相册.集市等丰富强大的互联网功能体 ...

  9. BZOJ3555 [Ctsc2014]企鹅QQ[暴力+字符串hash]

    菜到自闭,一道省选小水题都能给我做繁. 要求有一位不同,则对每个串每一位暴力枚举把这一位删掉,放一个分隔符,算一下hash,插表,相似的都应该会被插入同一个桶.最后把hash统计一下即可.复杂度$O( ...

随机推荐

  1. JS高级——eval

    eval函数可以用来将字符串转换成JavaScript代码并且运行 <script> eval('var a=10'); console.log(a);//10 </script&g ...

  2. Python 之beautifulSoup4解析库

    一.节点选择器 from bs4 import BeautifulSoup if __name__ == '__main__': html = ''' <div> <ul> & ...

  3. Sybase_ASA 字符串拼接

    列转行并拼接字符串,使用LIST函数 SELECT LIST(T.NAME,',') FROM TAB_DEMO T;

  4. 在iOS项目中嵌入RN代码

    1:在项目跟目录下创建一个ReactComponent文件夹.目录结构如下: 2: 在ReactComponent文件夹下新建一个 package.json 文件 { "name" ...

  5. 模板中tempname与class区别

    前言 在分析traits编程之前, 我们需要对模板参数类型tempname和class有一定的了解, 要明白他们在哪些方面不同, 哪些方面相同, 这样才能对体会到traits编程的核心. 如果你已经明 ...

  6. 小实例 hangman game

    代码 #include <bits/stdc++.h> using namespace std; int bk[110]; string sj(int t) { string ans=&q ...

  7. php观察折模式

    <?php class Paper{ private $_observers = array(); public function register($sub){ $this->_obse ...

  8. models中,字段参数limit_choices_to的用法

    这里,在使用 ModelForm 渲染前端页面的前提下,对于 models 中的 ManyToManyField 类型字段会在 ModelForm 中被转化为 ModelMultipleChoiceF ...

  9. 53. Maximum Subarray(动态规划)

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  10. 《hello-world》第八次团队作业:Alpha冲刺-Scrum Meeting 5

    项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 <hello--worl ...