既然只有一位的不同,那么我们可以枚举这一位....

我们只需要快速地计算去掉某一位的$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的更多相关文章

  1. BZOJ 3555: [Ctsc2014]企鹅QQ hash

    3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/p ...

  2. 【BZOJ3555】[Ctsc2014]企鹅QQ hash

    [BZOJ3555][Ctsc2014]企鹅QQ Description PenguinQQ是中国最大.最具影响力的SNS(Social Networking Services)网站,以实名制为基础, ...

  3. [CTSC2014]企鹅QQ hash

    ~~~题面~~~ 题解: 通过观察可以发现,其实题目就是要求长度相等的字符串中有且只有1位字符不同的 ”字符串对“ 有多少. 因为数据范围不大, 所以考虑一种暴力至极的方法. 我们枚举是哪一位不同,然 ...

  4. 字符串Hash || BZOJ 3555: [Ctsc2014]企鹅QQ || P4503 [CTSC2014]企鹅QQ

    题面:[CTSC2014]企鹅QQ 题解:无 代码: #include<iostream> #include<cstring> #include<cstdio> # ...

  5. [bzoj3555]企鹅QQ(hash)

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

  6. bzoj3555: [Ctsc2014]企鹅QQ

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

  7. 【BZOJ3555】 [Ctsc2014]企鹅QQ

    BZOJ3555 [Ctsc2014]企鹅QQ Solution 只需要前缀Hash,然后考虑每一段的贡献就好了!!! 代码实现 #include<stdio.h> #include< ...

  8. 洛谷 P4503 [CTSC2014]企鹅QQ 解题报告

    P4503 [CTSC2014]企鹅QQ 题目背景 PenguinQQ是中国最大.最具影响力的SNS(Social Networking Services)网站,以实名制为基础,为用户提供日志.群.即 ...

  9. bzoj——3555: [Ctsc2014]企鹅QQ

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

随机推荐

  1. vue+hbuilder监听安卓返回键问题

    1.监听安卓返回键问题 效果:在一级页面按一下返回键提示退出应用,按两下退出应用;在其它页面中,按一下返回上个历史页面 1 2 import mui from './assets/js/mui.min ...

  2. Go net/http获取body中json格式数据

    Go net/http获取body中json格式数据 package main import ( "encoding/json" "fmt" "io/ ...

  3. SpringMVC控制器 跳转到jsp页面 css img js等文件不起作用 不显示

    今天在SpringMVC转发页面的时候发现跳转页面确实成功,但是JS,CSS等静态资源不起作用: 控制层代码: /** * 转发到查看培养方案详情的页面 * @return */ @RequestMa ...

  4. solr简介——(九)

    下载:     http://archive.apache.org/dist/lucene/solr/ 1.什么是solr Solr 是Apache下的一个顶级开源项目,采用Java开发,它是基于Lu ...

  5. 脚本病毒分析扫描专题2-Powershell代码阅读扫盲

    4.2.PowerShell 为了保障木马样本的体积很小利于传播.攻击者会借助宏->WMI->Powershell的方式下载可执行文件恶意代码.最近也经常会遇见利用Powershell通过 ...

  6. 【记录】尝试用QEMU模拟ARM开发板去加载并运行Uboot,kernel,rootfs【转】

    转自:https://www.crifan.com/try_use_qemu_emulate_arm_board_to_load_and_run_uboot_kernel_rootfs/ [背景] 手 ...

  7. 13 JSON-RPC: a tale of interfaces

    JSON-RPC: a tale of interfaces 27 April 2010 Here we present an example where Go's interfaces made i ...

  8. 【前端vue开发】vue开发watch检测的使用

    <span style="color:#006600;"><div id="app"> <input type="tex ...

  9. 虚拟机 CentOS7 64

    下载地址:https://www.centos.org/download/ 下载完后以后使用虚拟机安装即可

  10. java基础21 System类和Runtime类

    一.System系统类 1.1.System系统类 主要用于获取系统信息 1.2.System类的常用方法 arraycopy(Object src, int srcPos, Object dest, ...