BZOJ 2081 Poi2010 Beads Hash
来源:互联网 发布:luckydraw抽奖软件 编辑:程序博客网 时间:2024/06/14 08:33
题目大意:给定一个数字串,求所有的k满足当将这个数字串从左到右分成大小为k的块时不同的块数量最多 反转同构算一种
枚举k,对于每个k将不同的串插入哈希表去重
反转同构啥的每个串的哈希值乘一下反串的哈希值就行了
时间复杂度O(n/1+n/2+...+n/n)=O(nlogn)
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define M 200200#define BASE 200191#define MOD 999911657using namespace std;int n,ans,a[M];long long hash1[M],hash2[M],power[M];int stack[M],top;namespace Hash_Table{struct List{int hash_value;bool flag;List *next;List(int _,List *__):hash_value(_),flag(false),next(__) {}}*head[BASE];int tim[BASE],T;void Initialize(){++T;}bool& Hash(int hash){int pos=hash%BASE;if(tim[pos]!=T)tim[pos]=T,head[pos]=0x0;for(List *temp=head[pos];temp;temp=temp->next)if(temp->hash_value==hash)return temp->flag;return (head[pos]=new List(hash,head[pos]))->flag;}}int main(){using namespace Hash_Table;int i,j;cin>>n;for(i=1;i<=n;i++)scanf("%d",&a[i]);for(i=1;i<=n;i++)hash1[i]=(hash1[i-1]*BASE+a[i])%MOD;for(i=n;i;i--)hash2[i]=(hash2[i+1]*BASE+a[i])%MOD;for(power[0]=1,i=1;i<=n;i++)power[i]=power[i-1]*BASE%MOD;for(i=1;i<=n;i++){int cnt=0;Initialize();for(j=i;j<=n;j+=i){int l=j-i+1,r=j;long long _hash1=(hash1[r]-hash1[l-1]*power[r-l+1]%MOD+MOD)%MOD;long long _hash2=(hash2[l]-hash2[r+1]*power[r-l+1]%MOD+MOD)%MOD;bool &flag=Hash(_hash1*_hash2%MOD);if(!flag) ++cnt;flag=1;}if(cnt>ans) ans=cnt,top=0;if(cnt==ans) stack[++top]=i;}cout<<ans<<' '<<top<<endl;for(i=1;i<=top;i++)printf("%d%c",stack[i]," \n"[i==top]);return 0;}
0 0
- BZOJ 2081 Poi2010 Beads Hash
- BZOJ 2081 [Poi2010]Beads hash
- bzoj 2081: [Poi2010]Beads
- bzoj 2081 [Poi2010]Beads
- BZOJ 2081 [Poi2010] Beads
- BZOJ 2081 [Poi2010]Beads 哈希
- bzoj 2081: [Poi2010]Beads 哈希
- BZOJ 2081 Beads Hash
- bzoj 2081 [Poi2010]Beads 枚举+哈希
- BZOJ P2081[Poi2010]Beads
- [BZOJ2081][POI2010]Beads(hash)
- 2081: [Poi2010]Beads
- Hash Algorithm 初步 & BZOJ2081 POI2010 Beads
- [bzoj2081][POI2010]KOR-Beads(hash)
- POI2010 Beads
- 字符串hash+map——BZOJ2081/Luogu3498 [Poi2010]Beads
- BZOJ 2085 Poi2010 Hamsters Hash+倍增Floyd
- BZOJ 2085 [Poi2010]Hamsters Hash+倍增floyd
- 快速部署Python应用:Nginx+uWSGI配置详解
- 在Unity3D中控制动画播放和混合播放同时播放
- 关于event.cancelBubble和event.stopPropagation()的区别介绍
- JNI Tips
- 鸡蛋真贵,非土鸡蛋都要1.2元
- BZOJ 2081 Poi2010 Beads Hash
- 关于C++ const 的全面总结
- Unity3D行为树系统编程实现
- C++中const、volatile、mutable的用法
- 运算符重载之->
- Unity3D-HTTP网络层封装
- 结构体字节对齐
- AndroidStudio显示行号的设定方法
- poj 1411 Brackets Sequence