2015 多校联赛 ——HDU5371(manacher + 枚举)
10
2 3 4 4 3 2 2 3 4 4
Case #1: 9
要求找出一段数字。
将其分成3部分,第①和第②部分成回文字串,第②和第③部分成回文字串
用manacher算出各个点的回文后字串长度,然点枚举和半径(后部分稍不注意就超时
- -!!)
#include <cstdio>
#include <iostream>
#include <algorithm>
#define MAXN 100010
using namespace std; int n;
int d[MAXN];
int st[MAXN*2];
int p[MAXN*2];
int len;
void manacher()
{
int MaxId=0,id;
for(int i=0; i<len; i++)
{
if(MaxId>i)
p[i]=min(p[2*id-i],MaxId-i);
else
p[i]=1;
while(st[i+p[i]]==st[i-p[i]])
p[i]++;
if(p[i]+i>MaxId)
{
id=i;
MaxId=p[i]+i;
}
}
}
int main()
{
int T;
scanf("%d",&T);
for(int t=1; t<=T; t++)
{
scanf("%d",&n);
for(int i = 0; i <= 2*n+1; i++)
p[i] =0;
len = 0;
st[len++]= -2;
st[len++]= -1;
for(int i=1; i<=n; ++i)
{
scanf("%d",&st[len++]);
st[len++] = -1;
}
st[len] = 0;
manacher();
int maxans=1;
for(int i = 3; i < len; i+=2)
for(int j = maxans; j <= p[i]; j+=2)
{
if(p[j+i-1] >= j)
maxans = j;
}
printf("Case #%d: %d\n",t,(maxans)/2*3);
}
return 0;
}</span>
2015 多校联赛 ——HDU5371(manacher + 枚举)的更多相关文章
- 2015 多校联赛 ——HDU5334(构造)
Virtual Participation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 2015 多校联赛 ——HDU5353(构造)
Each soda has some candies in their hand. And they want to make the number of candies the same by do ...
- 2015 多校联赛 ——HDU5302(构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2015 多校联赛 ——HDU5294(最短路,最小切割)
Tricks Device Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2015 多校联赛 ——HDU5325(DFS)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- 2015 多校联赛 ——HDU5316(线段树)
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...
- 2015 多校联赛 ——HDU5323(搜索)
Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 2015 多校联赛 ——HDU5319(模拟)
Painter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- 2015 多校联赛 ——HDU5301(技巧)
Your current task is to make a ground plan for a residential building located in HZXJHS. So you must ...
随机推荐
- poj2029 Get Many Persimmon Trees
http://poj.org/problem?id=2029 单点修改 矩阵查询 二维线段树 #include<cstdio> #include<cstring> #inclu ...
- Linux命令及lamp搭建
单纯属于Linux的命令:1.强制卸载有依赖关系的软件包: rpm -e httpd-2.2.15-26.el6.x86_64 --nodeps(--nodeps表示无依赖)4.删除当前目录所有的文件 ...
- ASP.NET 访问项目网站以外的目录文件
简单的说,可以通过在 IIS 添加虚拟目录的方法做到,获取访问路径的时候就用 HttpContext.Current.Server.MapPath("~/xxx"); 的方式. 下 ...
- Andrew Ng机器学习第一章——单变量线性回归
监督学习算法工作流程 h代表假设函数,h是一个引导x得到y的函数 如何表示h函数是监督学习的关键问题 线性回归:h函数是一个线性函数 代价函数 在线性回归问题中,常常需要解决最小化问题.代价函数常用平 ...
- Python-面向对象(二)-Day7
1.字段 12.方法 43.属性 63.1.属性的基本使用 73.2.实例:对于主机列表 83.3.属性的两种定义方式 94.对于类的成员而言都有两种形式: 144.1.私有成员和公有成员的访问限制不 ...
- GIT入门笔记(12)- 删除文件、提交删除和恢复删除
在Git中,删除也是一个修改操作,我们实战一下, 1.先添加add一个新文件test.txt到Git并且提交commit到本地版本库: $ git add test.txt$ git commit - ...
- ASP.NET CORE系列【三】使用Entity Framework Core进行增删改查
身份验证 以前我们熟悉的web.config中配置的form验证,现在没有了.我们来看看在Core里面如何配置: 首先需要NuGet安装一个包:Microsoft.AspNetCore.Authent ...
- Python之格式化输出,初始编码以及运算符
一.题型 1.使用while循环输入 1 2 3 4 5 6 8 9 10 count = 0 while count < 10: count += 1 #count = count + ...
- 百度资深架构师带你深入浅出一致性Hash原理
一.前言 在解决分布式系统中负载均衡的问题时候可以使用Hash算法让固定的一部分请求落到同一台服务器上,这样每台服务器固定处理一部分请求(并维护这些请求的信息),起到负载均衡的作用. 但是普通的余数h ...
- Django ORM创建数据库
Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能. ...