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 ...
随机推荐
- 【资源分享】ArcFace Demo [Android]
虹软人脸识别引擎Android的Demo演示,可以直接下载使用. 下载地址: https://github.com/asdfqwrasdf/ArcFaceDemo readme: 工程如何使用? 下载 ...
- Error: Invoke-customs are only supported starting with Android O (--min-api 26)
项目报错: 完美解决: 在App下 gradle.build中Android标签中 添加以下内容: compileOptions { sourceCompatibility JavaVersion.V ...
- DedeCMS清空删除所有文档后新建文档信息ID从1开始
方法一.登录织梦后台,找到系统->系统设置->SQL命令行工具 分别运行以下命令: 清除表中的数据,删除所有文章: truncate table `dede_arctiny`; trunc ...
- c#核心基础-委托
委托是一个类型.C#中的委托是面向对象的,并且它是类型安全的 当创建委托实例的时候,创建的实例会包含一个调用列表,在调用列表中可以包含多个方法.每个方法称作一个调用实体.调用实体可以是静态方法,也可以 ...
- win10 家庭版不支持gpedit.msc的解决办法
win10 家庭版不支持gpedit.msc的解决办法 1.建立一个批处理文件内容如下: @echo off pushd "%~dp0" dir /b %systemroot%\W ...
- Managing Large State in Apache Flink®: An Intro to Incremental Checkpointing
January 23, 2018- Apache Flink, Flink Features Stefan Richter and Chris Ward Apache Flink was purpos ...
- Java线程状态转换
前言:对于Java线程状态方面的知识点,笔者总感觉朦朦胧胧,趁着最近整理资料,将Java线程状态方面的知识点总结归纳,以便加深记忆. 1.Java线程状态值 在Thread类源码中通过枚举为线程定义了 ...
- (四)Exploring Your Cluster
The REST API Now that we have our node (and cluster) up and running, the next step is to understand ...
- Spring Security(二十九):9.4.1 ExceptionTranslationFilter
ExceptionTranslationFilter is a Spring Security filter that has responsibility for detecting any Spr ...
- Mango 基础知识
1 mongdb和python交互的模块 pymongo 提供了mongdb和python交互的所有方法 安装方式: pip install pymongo 2 使用pymongo 1. 导入pymo ...