玄关,P3370 【模板】字符串哈希求调
  • 板块灌水区
  • 楼主hehonghao
  • 当前回复5
  • 已保存回复5
  • 发布时间2025/1/27 15:33
  • 上次更新2025/1/27 20:34:06
查看原帖
玄关,P3370 【模板】字符串哈希求调
547143
hehonghao楼主2025/1/27 15:33

这是题目

#include<bits/stdc++.h>
using namespace std;
char a[114514];
bool mp[7145140];
int mp2[7145140];
int n;
int mp3[7145140];
int mp4[7145140];
int hah(int x)
{
	int tmp=0;
	while(x!=0)
	{
		tmp=tmp*97+x%10;
		x/=10;
		tmp%=7142887;
	}
	return tmp;
}
int main()
{
	cin>>n;
	int k=n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		int len=strlen(a);
		int tmp=len*len;
		for(int j=0;j<=(len/2);j++)
			swap(a[j],a[len-j-1]);
		for(int j=0;j<len;j++)
		{
			tmp=tmp*131+a[j];
			tmp%=7142887;
		}
			tmp=hah(tmp);
		if(mp[tmp]==true&&mp2[tmp]==len&&mp3[tmp]==a[0])
		{
			k--;
		}
		int l=0;
		while(mp[tmp]==true&&mp2[tmp]!=len)
		{
			tmp=hah(tmp);
			l++;
		}
		while(mp[tmp]==true&&mp2[tmp]==len&&mp3[tmp]!=a[0])
		{
			tmp=hah(tmp);
			l++;
		}
		while(mp[tmp]==true&&mp2[tmp]==len&&mp3[tmp]==a[0]&&l!=mp4[tmp])
		{
			tmp=hah(tmp);
			l++;
		}
		mp[tmp]=true;
		mp2[tmp]=len;
		mp3[tmp]=a[0];
		mp4[tmp]=l;
	}
	cout<<k;
    return 0;
}

2025/1/27 15:33
加载中...