fzu 2137 奇异字符串
来源:互联网 发布:网络舆情监控的目的 编辑:程序博客网 时间:2024/06/10 16:15
hash大法,还不懂为什么要这要做,但是就是可以这样做,先当模板,类似问题可以套用。
#include"cstdio"#include"cstring"#include"cmath"#include"cstdlib"#include"iostream"#include"algorithm"using namespace std;typedef unsigned long long ll;const ll maxn=100100;ll hash[maxn],base[maxn];char s[maxn];void init(ll len){ ll seed=131; hash[0]=0;base[0]=1; for(ll i=1;i<=len;i++){ hash[i]=hash[i-1]*seed+s[i]; base[i]=base[i-1]*seed; }}ll gethash(ll L,ll R){ return hash[R]-hash[L-1]*base[R-L+1];}int main(){ int T; cin>>T; while(T--){ scanf("%s",s+1); ll len=strlen(s+1); init(len); ll ans=0; for(ll i=2;i<len;i++){ ll L=i-1,R=i+1; while(L>=1&&R<=len){ if(s[L]==s[i]||s[R]==s[i])break; if(gethash(L,i-1)==gethash(i+1,R)) ans+=(ll)(2*(i-L)+1)*(2*(i-L)+1); L--;R++; } } printf("%I64u\n",ans); } return 0;}
0 0
- fzu 2137 奇异字符串
- FZU Problem 2137 奇异字符串
- 字符串hash fzu 2137 奇异字符串
- FZU 2137 奇异字符串 字符串哈希
- 【FZU】Problem 2137 奇异字符串【后缀数组】
- FZU 2137 奇异字符串 后缀数组
- fzu 11月赛F (2137) 奇异字符串 后缀数组
- fzu 2137 字符串hash或者后缀数组
- FZU - 2154 - YesOrNo (字符串~)
- fzu 1926 填空 【kmp字符串匹配】
- fzu 1913 Easy Comparison(字符串)
- FZU - 2088 最长队名 (字符串排序)
- FZU 1606 Format the expression (字符串处理)
- FZU 2027 单词问题(字符串问题)
- fzu 2091 播放器(字符串栈模拟)
- FZU
- FZU
- FZU
- Leetcode中两个字符串匹配
- 20140521
- struts2配置文件中url传递参数中文乱码处理
- List 交集、并集、差集运算
- IOS开发找不到Library目录
- fzu 2137 奇异字符串
- 基于 Android 的 3D 视频样本代码
- IIS7.5 http 1.1 新建应用程序失败 ASP的网站
- 多址广播和广播的区别
- DAO 设计模式
- CSS的伪元素
- /proc/sysrq-trigger文件的强大功能
- Leetcode:Generate Parentheses
- cocos2d-x 中使用的android控件详细说明之webview