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 ...
随机推荐
- 面板JPanel,滚动面板JScrollPane,文本域JTextArea
[面板JPanel] 面板就是一个容器 每一个容器都可以有一个自己的独立的布局和组件,这些容器之间也不会互相干扰 //导入Java类 import javax.swing.*; import java ...
- 微信小程序(一),授权页面搭建
wxml代码如下: <!--pages/index2/index2.wxml--> <view class="index2Container"> <i ...
- 监控 redis 执行命令
监控 redis 执行命令 Intro 最近在用 redis 的时候想看看执行了哪些命令,于是发现了 redis-cli 提供的 Monitor 命令,直接使用这个就可以监控执行的大部分 redis ...
- Windows系统资源监控
1.windows自带系统资源监控工具 2.Windows监控的数据来源:Performance Counters 2.1 Performance Counter架构 2.2 Performance ...
- Saltstack_使用指南01_部署
1. 主机规划 服务器名称 操作系统版本 内网IP 外网IP(模拟) Hostname 部署模块 salt100 CentOS7.5 172.16.1.100 10.0.0.100 salt100 s ...
- Java开发学习心得(二):Mybatis和Url路由
目录 Java开发学习心得(二):Mybatis和Url路由 1.3 Mybatis 2 URL路由 2.1 @RequestMapping 2.2 @PathVariable 2.3 不同的请求类型 ...
- IDEA包名显示设置
项目结构视图右上角那个齿轮 选择[Compact Empty Middle Packages],包会合并显示 [Hide Empty Middle Packages]去掉前面的√,不分层级显示
- 网络编程_tcp与dup协议简单应用
老师的博客:http://www.cnblogs.com/Eva-J/articles/8066842.html 计算机网络基础 :http://www.cnblogs.com/Eva-J/artic ...
- 如何在查看docker container内进程信息,与宿主机上进程信息的映射关系
docker container内运行的进程,在宿主机上,通过ps也是能够查到的,但是在不熟悉命令的时候,无法快速找到他们的关系. 这里科普一个基础命令 docker top 1. 找到容器的id d ...
- Vue-Router的Hash说起的URL相关知识
最近被问到VueRouter的两种模式的区别,答:Hash模式url上有#号,History模式url上没有#.完! 也不知道这么回答对不对,就看了看资料,发现也就是这个意思吧! Vue-Router ...