POJ--3974 Palindrome(回文串,hash)
链接:点击这里
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstring>
using namespace std;
#define maxn 1000005
#define LL long long
#define ull unsigned long long
;
ull p[maxn+],f[maxn],ff[maxn];
int main(){
p[]=;
;j<=maxn;j++){
p[j]=p[j-]*P;
}
string s;
;
while(cin>>s){
if(s=="END") break;
f[]=,ff[]=;
;
int len=s.size();
;j<=len;j++){
f[j]=f[j-]*P+s[j-]-;
}
;j--){
ff[j]=ff[j+]*P+s[j-]-;
}
;j<=len;j++){
,r=min(len-j,j),mx=;
while(l<=r){ // 偶数
;
,r1=j;
,r2=j+mid;
LL ll=f[r1]-f[l1-]*p[r1-l1+];
LL rr=ff[l2]-ff[r2+]*p[r2-l2+];
if(ll==rr){
mx=max(mx,mid);
l=mid+;
};
}
ans=max(ans,*mx);
l=,r=min(len-j,j-),mx=;
while(l<=r){ //奇数
;
;
,r2=j+mid;
LL ll=f[r1]-f[l1-]*p[r1-l1+];
LL rr=ff[l2]-ff[r2+]*p[r2-l2+];
if(ll==rr){
mx=max(mx,mid);
l=mid+;
};
}
ans=max(ans,*mx+);
}
//cout<<ans<<endl;
printf("Case %d: %d\n",tot++,ans);
}
;
}
POJ--3974 Palindrome(回文串,hash)的更多相关文章
- hdu 1159 Palindrome(回文串) 动态规划
题意:输入一个字符串,至少插入几个字符可以变成回文串(左右对称的字符串) 分析:f[x][y]代表x与y个字符间至少插入f[x][y]个字符可以变成回文串,可以利用动态规划的思想,求解 状态转化方程: ...
- poj 1159 dp回文串
题意:添加最少的字符使之成为回文串 #include<cstdio> #include<iostream> #include<algorithm> #include ...
- 洛谷T89644 palindrome回文串
洛谷 T89643 回文串(并查集) 洛谷:https://www.luogu.org/problem/T89643 题目描述 由于 Kiana 实在是太忙了,所以今天的题里面没有 Kiana. 有一 ...
- POJ 3974 回文串-Manacher
题目链接:http://poj.org/problem?id=3974 题意:求出给定字符串的最长回文串长度. 思路:裸的Manacher模板题. #include<iostream> # ...
- poj 3280 Cheapest Palindrome ---(DP 回文串)
题目链接:http://poj.org/problem?id=3280 思路: dp[i][j] :=第i个字符到第j个字符之间形成回文串的最小费用. dp[i][j]=min(dp[i+1][j]+ ...
- POJ 3280 Cheapest Palindrome(区间DP求改成回文串的最小花费)
题目链接:http://poj.org/problem?id=3280 题目大意:给你一个字符串,你可以删除或者增加任意字符,对应有相应的花费,让你通过这些操作使得字符串变为回文串,求最小花费.解题思 ...
- Gym - 100570E:Palindrome Query (hash+BIT+二分维护回文串长度)
题意:给定字符串char[],以及Q个操作,操作有三种: 1:pos,chr:把pos位置的字符改为chr 2:pos:问以pos为中心的回文串长度为多长. 3:pos:问以pos,pos+1为中心的 ...
- 回文串---Palindrome
POJ 3974 Description Andy the smart computer science student was attending an algorithms class whe ...
- POJ 3974 - Palindrome - [字符串hash+二分]
题目链接:http://poj.org/problem?id=3974 Time Limit: 15000MS Memory Limit: 65536K Description Andy the sm ...
- [LeetCode] Longest Palindrome 最长回文串
Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...
随机推荐
- GitHub和75亿美金
如果你是看到了75亿进来的,还在纳闷前面那个github的是个什么,你可以走人了?如果你进来是想看到微软两个字的,请继续. 微软以75亿美金的股票收购Github这件事情,从周六一早我爬山到香山琉璃塔 ...
- Python第八天 模块 包 全局变量和内置变量__name__ Python path
Python第八天 模块 包 全局变量和内置变量__name__ Python path 目录 Pycharm使用技巧(转载) Python第一天 安装 shell 文件 Pyt ...
- Python Learning: 01
After a short period of new year days, I found life a little boring. So just do something funny--Py ...
- 0106笔记--vc2012 打印堆栈
清空icound 菜单 调试-->选项和设置--->常规--->启用调试助手 要把在未经处理的异常上展开调用堆栈选中: 然后就有
- Configuring High Availability and Consistency for Apache Kafka
To achieve high availability and consistency targets, adjust the following parameters to meet your r ...
- 单元测试(qunit)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- jenkins乱码解决问题
1.jenkins控制台线上乱码解决 系统管理——系统设置,添加编码环境变量 zh.CH.UTF-8 2.java启动后,tomcat日志显示乱码,原因是环境变量没有带过去,因此shell脚本头部需要 ...
- 小小知识点(五)——MATLAB对复数的操作
MATLAB程序 a=3+4*i %复数 real(a) %求复数的实部 imag(a) %求复数的虚部 abs(a) %求复数的模 angle(a) %求复数的相位 conj(a) %求复数的复共轭 ...
- Tutorial 01_熟悉常用的Linux操作和Hadoop操作
(一)熟悉常用的Linux 操作cd 命令:切换目录 (1) 切换到目录“/usr/local” (2) 切换到当前目录的上一级目录 (3) 切换到当前登录Linux 系统的用户的自己的主文件夹 ...
- Django rest framework 源码分析 (1)----认证
一.基础 django 2.0官方文档 https://docs.djangoproject.com/en/2.0/ 安装 pip3 install djangorestframework 假如我们想 ...