链接:点击这里

#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)的更多相关文章

  1. hdu 1159 Palindrome(回文串) 动态规划

    题意:输入一个字符串,至少插入几个字符可以变成回文串(左右对称的字符串) 分析:f[x][y]代表x与y个字符间至少插入f[x][y]个字符可以变成回文串,可以利用动态规划的思想,求解 状态转化方程: ...

  2. poj 1159 dp回文串

    题意:添加最少的字符使之成为回文串 #include<cstdio> #include<iostream> #include<algorithm> #include ...

  3. 洛谷T89644 palindrome回文串

    洛谷 T89643 回文串(并查集) 洛谷:https://www.luogu.org/problem/T89643 题目描述 由于 Kiana 实在是太忙了,所以今天的题里面没有 Kiana. 有一 ...

  4. POJ 3974 回文串-Manacher

    题目链接:http://poj.org/problem?id=3974 题意:求出给定字符串的最长回文串长度. 思路:裸的Manacher模板题. #include<iostream> # ...

  5. poj 3280 Cheapest Palindrome ---(DP 回文串)

    题目链接:http://poj.org/problem?id=3280 思路: dp[i][j] :=第i个字符到第j个字符之间形成回文串的最小费用. dp[i][j]=min(dp[i+1][j]+ ...

  6. POJ 3280 Cheapest Palindrome(区间DP求改成回文串的最小花费)

    题目链接:http://poj.org/problem?id=3280 题目大意:给你一个字符串,你可以删除或者增加任意字符,对应有相应的花费,让你通过这些操作使得字符串变为回文串,求最小花费.解题思 ...

  7. Gym - 100570E:Palindrome Query (hash+BIT+二分维护回文串长度)

    题意:给定字符串char[],以及Q个操作,操作有三种: 1:pos,chr:把pos位置的字符改为chr 2:pos:问以pos为中心的回文串长度为多长. 3:pos:问以pos,pos+1为中心的 ...

  8. 回文串---Palindrome

    POJ   3974 Description Andy the smart computer science student was attending an algorithms class whe ...

  9. POJ 3974 - Palindrome - [字符串hash+二分]

    题目链接:http://poj.org/problem?id=3974 Time Limit: 15000MS Memory Limit: 65536K Description Andy the sm ...

  10. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

随机推荐

  1. Redis订阅与发布

    发布与订阅模型在许多编程语言中都有实现,也就是我们经常说的设计模式中的一种--观察者模式.在一些应用场合,例如发送方并不是以固定频率发送消息,如果接收方频繁去咨询发送方,这种操作无疑是很麻烦并且不友好 ...

  2. 解决TOC与目录导航冲突问题

    TOC是指markdown的TOC; 目录导航是指博客园中各个博主提供的各种目录导航. 现在改换markdown写博文了,我喜欢使用TOC作为目录,让大家了解博文的内容,也喜欢用"目录导航& ...

  3. python2和python3的一些差别

    未来python3是主流,但还是因为一部分原因,很多项目还在用python2.python3是不兼容python2的,做了一些优化和改进 1.字符编码 python2:ascii编码 python3: ...

  4. Centos7VMware虚拟机最小化安装后,安装Tenda U12 USB无线网卡驱动

    前几天买下了Tenda U12 USB 无线网卡 ,想连接上无线玩玩,可惜买下折腾了一周才解决他它驱动问题,前后在VMware上装了十多次,测试了好几个内核版本才搞定,好了废话不多说,分享下我安装过程 ...

  5. C# Math的说有函数 以及说明

    Math.Abs(x)                                      x绝对值 Math.Acos(x)                                  ...

  6. C#基础知识之类和结构体

    虽然项目中一直在使用类.结构体等类型,仔细琢磨,还真无法系统的说出个所以然.记录一下类.结构体.类和结构体区别 一.类 对于类,大家都特别熟悉.简单的介绍一下类的结构,然后记录一下Class需要注意的 ...

  7. maven 出现错误 -source 1.5 中不支持 diamond 运算符

    mvn clean package -DskipTests 出现如下错误: -source 1.5 中不支持 diamond 运算符 [ERROR] (请使用 -source 7 或更高版本以启用 d ...

  8. HBase 数据模型

    在HBase中,数据是存储在有行有列的表格中.这是与关系型数据库重复的术语,并不是有用的类比.相反,HBase可以被认为是一个多维度的映射. HBase数据模型术语 Table(表格) 一个HBase ...

  9. Mysql共享锁、排他锁、悲观锁、乐观锁及其使用场景

    一.相关名词 |--表级锁(锁定整个表) |--页级锁(锁定一页) |--行级锁(锁定一行) |--共享锁(S锁,MyISAM 叫做读锁) |--排他锁(X锁,MyISAM 叫做写锁) |--悲观锁( ...

  10. Spring Security(三十五):Part III. Testing

    This section describes the testing support provided by Spring Security. 本节介绍Spring Security提供的测试支持. ...