4503 企鹅QQ
QQ给了你ccf多少钱,我微信给你双倍(逃
记得前几天在夏令营的时候还是一个绿题,这就升蓝题了?
提炼题目
当以两个字符串,当且仅当|a|=|b|并且恰好只有一位是不同的,这样叫做两个字符串相似
现在给问给定n个长度为l的字符串,问两两之间有多少相似的字符串
emmmmm
我这个菜鸡不会啊
不过感觉hash还是比线段树树状数组这些东西好的,真的,最起码有点思路了
在这里补充一个字符串小常识,用cin输入字符的时候会自动过滤空格,用scanf会包括在里面,zp老师之前就告诉我们
还有就是打代码的时候需要必要的时候加上空格,好看
这里使用进制hash来计算
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int base=2333;
const int SIZE=30005;
int n,l,s;
char c;
ll hash[SIZE][205],power[205];
ll t[SIZE];
int main()
{
cin>>n>>l>>s;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=l;j++)
{
cin>>c;
hash[i][j]=hash[i][j-1]*base+c;//进制
}
}
power[0]=1;
for(int i=1;i<=l;i++)
{
power[i]=power[i-1]*base;
}
int ans=0;
for(int i=1;i<=l;i++)
{
for(int j=1;j<=n;j++)
{
t[j]=hash[j][l]-(hash[j][i]-hash[j][i-1]*base)*power[l-i]-hash[j][i-1]*(power[l-i+1]-power[l-i]);
}//计算区间hash值
sort(t+1,t+n+1);
int temp=1;
for(int j=1;j<n;j++)
{
if(t[j]!=t[j+1]) temp=1;
else ans+=temp++;
}
}
cout<<ans<<endl;
return 0;
}