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 ...
随机推荐
- 关于sqlserver字符类型查询条件区分大小写
在写sql的查询时 如下: select * from Users where username='WangE' select * from Users where username='wange' ...
- 获取spring security用户相关信息
在JSP中获得 使用spring security的标签库 在页面中引入标签 <%@ taglib prefix="sec" uri="http://www.spr ...
- Linux电源管理(9)_wakelocks【转】
1. 前言 wakelocks是一个有故事的功能. wakelocks最初出现在Android为linux kernel打的一个补丁集上,该补丁集实现了一个名称为"wakelocks&quo ...
- windows搭建golang环境
由于墙的存在,很多网址无法下载,推荐https://studygolang.com/dl去下载. windows需要配置几个环境变量,我是下载的压缩文件,所以需要自己配置,通过安装程序安装的应该不需要 ...
- 重装助手教你如何禁用Windows 10快速启动
快速启动是首先在Windows 8中实现并延续到Windows 10的功能,可在启动PC时提供更快的启动时间.它是一个方便的功能,也是大多数人在不知情的情况下使用的功能,但还有一些功能会在他们掌握新P ...
- Zookeeper与Kafka基础概念和原理
1.zookeeper概念介绍 在介绍ZooKeeper之前,先来介绍一下分布式协调技术,所谓分布式协调技术主要是用来解决分布式环境当中多个进程之间的同步控制,让他们有序的去访问某种共享资源,防止造成 ...
- bootstrapt 使用遇到问题
1.布局的时候什么时候用xs,sm,md,lg? small grid (≥ 768px) = .col-sm-*, medium grid (≥ 992px) = .col-md-*, large ...
- c# 判断一个string[]是否全包含另一个string[]
// list = normalList.Except(repairList).ToList(); //差集 // list = normalList.Union(repairList).ToList ...
- 微信小程序支付,带java源码
先说下这个的背景吧... 本人是做java后端的,自认为还有很大的发展空间(嘻嘻,你懂的),看过一段时间的小程序可是没有支付成功...最近公司要做小程序项目,老大让我看下小程序,折腾了好几天,参照着h ...
- linux文件系統详解
什么是文件系统 文件系统是操作系统用于明确磁盘或分区上的文件的方法和数据结构,即在存储设备(磁盘)上组织文件的方法.操作系统中负责管理和存储文件信息的软件结构称为文件管理系统,简称文件系统. 从系统角 ...