BZOJ3555 [Ctsc2014]企鹅QQ


Solution

只需要前缀Hash,然后考虑每一段的贡献就好了!!!

代码实现

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi()
{
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
#define ull unsigned long long
const int N=30010,L=210;
const ull Base=19260817,Base1=19491001,Base2=23333;
ull Hash[N][L],tmp[N],pw[L];
int n,l,S;
ll ans;
char s[N];
void hAsh(int id)
{
    for(int i=1;i<=l;i++)
        Hash[id][i]=Hash[id][i-1]*Base+s[i];
}
ull getHash(int id,int l,int r)
{
    if(l>r)return 0;
    return Hash[id][r]-Hash[id][l-1]*pw[r-l+1];
}
int main()
{
    n=gi();l=gi();S=gi();
    pw[0]=1;
    for(int i=1;i<=l;i++)
        pw[i]=pw[i-1]*Base;
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s+1);
        hAsh(i);
    }
    for(int j=1;j<=l;j++)
    {
        for(int i=1;i<=n;i++)tmp[i]=Hash[i][j-1]*pw[l-j]+getHash(i,j+1,l);
        sort(tmp+1,tmp+n+1);
        int now=1;
        for(int i=2;i<=n;i++)
        {
            if(tmp[i]==tmp[i-1])ans+=now,now++;
            else now=1;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

【BZOJ3555】 [Ctsc2014]企鹅QQ的更多相关文章

  1. bzoj3555: [Ctsc2014]企鹅QQ

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

  2. bzoj3555: [Ctsc2014]企鹅QQ (Hash)

    枚举每个分段的点,每次O(n)更新左边和右边的hash值 然后用双指针O(n)计算答案 #include<stdio.h> #include<string.h> #includ ...

  3. BZOJ3555 [Ctsc2014]企鹅QQ 题解

    题目大意: 有一些字符串,求其中两个等长且恰好只有一位不同的字符串的对数. 思路: Hash大法好!正着倒着各来一遍(底数不同),之后枚举不同的那一位,前后两段拼起来之后为了有区分前面一部分再乘一个数 ...

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

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

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

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

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

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

  7. [BZOJ3555] [Ctsc2014]企鹅QQ(Hash)

    传送门 可以枚举被删除的位置,然后用hash表判重,然而网上好多题解都是用 sort 判重的. 不知道为什么,int 总是过不了,换成 long long 或者是 unsigned long long ...

  8. bzoj3555 [Ctsc2014]企鹅QQ——字符串哈希

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3555 很久以前就讲过哈希,但一直没写过题,所以这是哈希第一题! 哈希就是把一个字符串映射成一 ...

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

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

随机推荐

  1. EasyUI DataGrid 获得分页信息

    var b = $('#SBDiv_1_DateGrid').datagrid('options'); console.info(b); 具体需要哪些字段,可以通过火狐debug,然后自己找需要的信息 ...

  2. python上下文管理协议

    所谓上下文管理协议,就是咱们打开文件时常用的一种方法:with __enter__(self):当with开始运行的时候触发此方法的运行 __exit__(self, exc_type, exc_va ...

  3. CMDB 配置管理数据库

  4. delphi 中如何处理“幽灵”、“熔断”?(转载)

    原始连接:http://dannywind.nl/delphi/meltdown-spectre-and-delphi/ Meltdown, Spectre and Delphi Don’t pani ...

  5. python递归和二分法

    一.递归 1.递归就是自己调用自己 def fn(n): print(n) fn(n+1) fn(1) #递归深度官方1000 一般都递归到998 2.树形结构的遍历 import os def fn ...

  6. 多分类评价指标python代码

    from sklearn.metrics import precision_score,recall_score print (precision_score(y_true, y_scores,ave ...

  7. Servlet中(Session、cookies、servletcontext)的基本用法

    /req: 用于获得客户端(浏览器)的信息 //res: 用于向客户端(浏览器)返回信息 1.session的设置:            //得到和req相关联的session,如果没有就创建ses ...

  8. scrapy知识积累

    Scrapy 中文文档https://scrapy-chs.readthedocs.io/zh_CN/latest/intro/overview.html 创建项目 scrapy startproje ...

  9. 【服务器】Nginx文件配置

    nginx.conf文件 #运行用户 user nobody; #启动进程,通常设置成和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 #error_log lo ...

  10. python模块:shutil

    """Utility functions for copying and archiving files and directory trees. XXX The fun ...