字符串hash+map——BZOJ2081/Luogu3498 [Poi2010]Beads
来源:互联网 发布:欧米伽网络是培训吗 编辑:程序博客网 时间:2024/05/23 11:49
http://www.lydsy.com/JudgeOnline/problem.php?id=2081
https://www.luogu.org/problem/show?pid=3498
一题字符串hash
一开始因为各种原因导致我TLE和WA等等。。。。。
发现基数base会有各种问题,注意一下就好了
我的方法是hash+map映射,所以long long自然溢出不影响结果
所以我没取模。。。
番外:我取的基数base一开始取了n+1WA掉了,后来改成2333和6666都过了。。。
#include<bits/stdc++.h>#define ll long longusing namespace std;int a[200001],ans[200001];ll ba,h1[200001],h2[200002],po[200001];map<ll,bool>b;int main(){ int n;scanf("%d",&n);ba=2333; for(int i=1;i<=n;i++)scanf("%d",&a[i]); po[0]=1;for(int i=1;i<=n;i++)po[i]=po[i-1]*ba; for(int i=1;i<=n;i++)h1[i]=h1[i-1]*ba+(ll)a[i]; for(int i=n;i>0;i--)h2[i]=h2[i+1]*ba+(ll)a[i]; int ma,sum;ma=sum=0; for(int i=1;ma*i<=n&&i<=n;i++){ b.clear(); int p=0; for(int j=1;j+i-1<=n;j+=i){ ll ha1,ha2,x=j-1,y=j+i-1; ha1=h1[y]-h1[x]*po[y-x]; x++;y++; ha2=h2[x]-h2[y]*po[y-x]; if(!b[ha1]||!b[ha2]){ p++; b[ha1]=b[ha2]=1; } } if(p>ma){ma=p;sum=1;ans[1]=i;} else if(p==ma)ans[++sum]=i; } printf("%d %d\n%d",ma,sum,ans[1]); for(int i=2;i<=sum;i++)printf(" %d",ans[i]);}
1 0
- 字符串hash+map——BZOJ2081/Luogu3498 [Poi2010]Beads
- [BZOJ2081][POI2010]Beads(hash)
- Hash Algorithm 初步 & BZOJ2081 POI2010 Beads
- [bzoj2081][POI2010]KOR-Beads(hash)
- BZOJ2081: [Poi2010]Beads
- BZOJ2081 [Poi2010]Beads
- BZOJ2081[POI2010] Beads
- BZOJ2081: [Poi2010]Beads 哈希
- bzoj2081: [Poi2010]Beads
- 【bzoj2081】[Poi2010]Beads
- 【BZOJ2081】【Poi2010(17th)】Beads RKhash+hash表 请记住这个神一样的数:200019
- BZOJ 2081 Poi2010 Beads Hash
- BZOJ 2081 [Poi2010]Beads hash
- bzoj2081 Beads
- POI2010 Beads
- 字符串哈希-洛谷P3498 [POI2010]KOR-Beads
- bzoj 2081: [Poi2010]Beads
- 2081: [Poi2010]Beads
- 自定义shell脚本采集日志信息
- Spring声明式事务配置管理方法
- Error:Security problem ,see jack server log解决方法,Linux多人使用一台服务器编译出现端口占用。
- RecyclerView的使用和封装
- 使用Xshell连接服务器SSH
- 字符串hash+map——BZOJ2081/Luogu3498 [Poi2010]Beads
- SelectSort 选择排序
- centos 7配置ip地址
- OpenCV_(HougLines transform)霍夫变换检测直线
- 基础算法——快速排序
- Android 自定义View学习之文字绘制
- UItableveiw的一些使用
- Linux系统内核分析实验——system_call中断处理过程
- JAVA HttpURLConnection Post方式提交传递参数