luoguP4503 [CTSC2014]企鹅QQ hash

既然只有一位的不同,那么我们可以枚举这一位....
我们只需要快速地计算去掉某一位的$hash$值....
由于$hash(S) = \sum s[i] * seed^i$,因此去掉第$i$位的权值只需要用$hash(S) - s[i] * seed^i$
由于字符串两两不相同,因此不存在两个串去掉$i$和去掉$j$仍会保持相似
这样子就可以做到不重的统计
复杂度$O(nL \log n)$
应该是可以用基排优化到$O(nL)$的...
#include <map>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; #define ll long long
#define ri register int
#define ull unsigned long long
#define rep(io, st, ed) for(ri io = st; io <= ed; io ++)
#define drep(io, ed, st) for(ri io = ed; io >= st; io --)
#define gc getchar
inline int read() {
int p = ; char c = gc();
while(c > '' || c < '') c = gc();
while(c >= '' && c <= '') p = p * + c - '', c = gc();
return p;
} const int seed = ;
const int sid = ;
const int pid = ; int n, L, S;
char s[sid][pid];
ull wei[sid], val[sid], q[sid]; int main() {
n = read(); L = read(); S = read();
wei[] = ;
rep(i, , L) wei[i] = wei[i - ] * seed; rep(i, , n) {
scanf("%s", s[i] + );
rep(j, , L) val[i] += s[i][j] * wei[j];
} ll ans = ;
rep(i, , L) {
rep(j, , n)
q[j] = val[j] - s[j][i] * wei[i];
sort(q + , q + n + );
for(ri i = , j = ; i <= n; i = j + ) {
j = i;
while(q[j + ] == q[i]) j ++;
ans += (j - i + ) * (j - i) / ;
}
} printf("%lld\n", ans);
return ;
}
luoguP4503 [CTSC2014]企鹅QQ hash的更多相关文章
- BZOJ 3555: [Ctsc2014]企鹅QQ hash
3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...
- 【BZOJ3555】[Ctsc2014]企鹅QQ hash
[BZOJ3555][Ctsc2014]企鹅QQ Description PenguinQQ是中国最大.最具影响力的SNS(Social Networking Services)网站,以实名制为基础, ...
- [CTSC2014]企鹅QQ hash
~~~题面~~~ 题解: 通过观察可以发现,其实题目就是要求长度相等的字符串中有且只有1位字符不同的 ”字符串对“ 有多少. 因为数据范围不大, 所以考虑一种暴力至极的方法. 我们枚举是哪一位不同,然 ...
- 字符串Hash || BZOJ 3555: [Ctsc2014]企鹅QQ || P4503 [CTSC2014]企鹅QQ
题面:[CTSC2014]企鹅QQ 题解:无 代码: #include<iostream> #include<cstring> #include<cstdio> # ...
- [bzoj3555]企鹅QQ(hash)
3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 1645 Solved: 616[Submit][Statu ...
- bzoj3555: [Ctsc2014]企鹅QQ
将字符串hash.不难写.然而1.注意用longlong2.数组大小注意...3.似乎别人都用的unsigned long long ?. #include<cstdio> #includ ...
- 【BZOJ3555】 [Ctsc2014]企鹅QQ
BZOJ3555 [Ctsc2014]企鹅QQ Solution 只需要前缀Hash,然后考虑每一段的贡献就好了!!! 代码实现 #include<stdio.h> #include< ...
- 洛谷 P4503 [CTSC2014]企鹅QQ 解题报告
P4503 [CTSC2014]企鹅QQ 题目背景 PenguinQQ是中国最大.最具影响力的SNS(Social Networking Services)网站,以实名制为基础,为用户提供日志.群.即 ...
- bzoj——3555: [Ctsc2014]企鹅QQ
3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 2617 Solved: 921[Submit][Statu ...
随机推荐
- Python的类变量和成员变量、类静态方法和类成员方法
先说明几个相关的术语:attribute.function.method. attribute:类对象的数据成员.我们经常会在Python代码出错时遇到:“AttributeError: 'My_Cl ...
- 2016.07.15——istringstream测试
istringstream测试 1.istringstream strcin(str),字符串(str)可以包括多个单词,单词之间使用空格分开 #include "stdafx.h" ...
- css给表格每一列设置不同的样式
第一列#id table tr td:first-child{ overflow: visible; }第二列table tr td:first-child+td{color:#666;}第三列tab ...
- 【Python学习笔记】使用Python进行T检验
使用Python进行T检验 所需要用到的第三方库有scipy. 均可以通过pip直接安装. pip install scipy numpy 引入第三方库 from scipy import stats ...
- kworker内核工作队列详解
工作队列是另一种将工作推后执行的形式,它可以把工作交给一个内核线程去执行,这个下半部是在进程上下文中执行的,因此,它可以重新调度还有睡眠. 区分使用软中断/tasklet还是工作队列比较简单,如 ...
- 使用ubifs格式的根文件系统
配置内核,使其支持ubifs文件系统 1)Device Drivers --->Memory Technology Device (MTD) support --->UBI - Uns ...
- lombok java代码助手
是不一个不错的代码生成工具,可以实现将代码更精简,且不失代码效率的一种不错的方法 https://www.cnblogs.com/qnight/p/8997493.html 通过java bean v ...
- RabbitMQ--Publish/Subscribe(五)
上篇文章中,我们实现了不同consumer接收不同级别的日志,这篇文章中,不以日志级别,使用不同日志来源.比如kernel.*.*.critical. 这就要使用topic exchange完成了.将 ...
- 03 Go 1.3 Release Notes
Go 1.3 Release Notes Introduction to Go 1.3 Changes to the supported operating systems and architect ...
- Codeforces 225C Barcode(矩阵上DP)
题目链接:http://codeforces.com/contest/225/problem/C 题目大意: 给出一个矩阵,只有两种字符'.'和'#',问最少修改多少个点才能让每一列的字符一致,且字符 ...