Hdu 4513 吉哥系列故事——完美队形II (manacher变形)
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4513
题目描述:
打完题目描述了,点开题目,发现题目是中文,orz.jpg。果断又删掉了,习惯真可怕.......
解题思路:
刚开始,我先manacher求出以 i 为中心的回文串半径存入vis,然后暴力循环每一个位置是不是最长的完美队列。果断T了,胡乱改了几处依旧T。突然灵机一动,发现可以在跑vis数组的时候加一些判定条件,然后直接求出max(vis[i])即可。
学习算法是次要,理解算法思想,锻炼思维灵敏逻辑缜密才最重要。
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std; typedef long long LL;
const int maxn = ;
int vis[maxn*], a[maxn], b[maxn*]; bool judge (int x, int y)
{
for (int i=x+; i<=y/; i++)
if (a[i]<a[i-])
return false;
return true;
} void manacher (int s[], int len)
{
int l = ;
b[l ++] = -;
b[l ++] = -; for (int i=; i<len; i++)
{
b[l ++] = a[i];
b[l ++] = -;
}
b[l] = ; int mx = , id = , ans = ; for (int i=; i<l; i++)
{
vis[i] = mx > i ? min (vis[*id-i], mx-i):; while (b[i-vis[i]] == b[i+vis[i]] && (b[i-vis[i]]==- || b[i-vis[i]]<=b[i-vis[i]+])) vis[i] ++; if (i + vis[i] > mx)
{
mx = i + vis[i];
id = i;
}
ans = max (ans, vis[i]);
} printf ("%d\n", ans - );
} int main ()
{
int T, n;
scanf ("%d", &T); while (T --)
{
scanf ("%d", &n);
for (int i=; i<n; i++)
scanf ("%d", &a[i]); manacher(a, n);
}
return ;
}
Hdu 4513 吉哥系列故事——完美队形II (manacher变形)的更多相关文章
- HDU 4513 吉哥系列故事――完美队形II(Manacher)
题目链接:cid=70325#problem/V">[kuangbin带你飞]专题十六 KMP & 扩展KMP & Manacher V - 吉哥系列故事――完美队形I ...
- HDU 4513 吉哥系列故事——完美队形II manacher
吉哥系列故事——完美队形II Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希 ...
- HDU 4513 吉哥系列故事――完美队形II
http://acm.hdu.edu.cn/showproblem.php?pid=4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) ...
- hdu 4513 吉哥系列故事——完美队形II (manachar算法)
吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) P ...
- HDU 4513 吉哥系列故事——完美队形II(Manacher)
Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成 ...
- HDU 4513 吉哥系列故事——完美队形II (Manacher变形)
题意:假设有n个人按顺序的身高分别是h[1], h[2] ... h[n],从中挑出一些人形成一个新的队形,新的队形若满足以下要求,则就是新的完美队形: 1.连续的 2.形成回文串 3.从左到中间那 ...
- HDU 4513 吉哥系列故事——完美队形II( Manacher变形 )
链接:传送门 思路:根据完美队形的定义,可以得知,完美队形实质上是 回文串 + 序列出现峰,因为是在回文串中再次增加了一个要求,所以可以对 Manacher 进行改造,改造的部分应该为暴力匹配的循环 ...
- HDU 4513 吉哥系列故事——完美队形II
变形的Manacher算法,在扩展的时候要加入限制条件,满足题目中说的从左到中间身高不减. 其他地方倒是没有什么改动.. //#define LOCAL #include <iostream&g ...
- HDU - 4513 吉哥系列故事――完美队形II(manacher)
1.找出一个最长的回文子串,要求中间的值最大,然后向两侧递减. 2.判断条件改为:Ma[i+Mp[i]]==Ma[i-Mp[i]]&&Ma[i-Mp[i]]<=Ma[i-Mp[i ...
随机推荐
- linux 标准i2c接口(一)
一:I2C设备操作方式: 1. 应用程序操作法:i2c的设备的驱动可以直接利用linux内核提供的i2c-dev.c文件提供的ioctl函数接口在应用层实现对i2c设备的读写,但是在应用层使用ioc ...
- My app status is Ready for Sale but I cannot see my app on the App Store. Why? 为什么审核通过后 appstore中搜不到我的app
这是苹果的官方解答 The following factors could prevent your app from showing up on the App Store: Make sure t ...
- vs2010 msvcr100.DLL 丢失!!! 用release 就可以了
- Marlin固件之—:基础入门与測试
一.Marlin的简介 Marlin固件是一个3D打印的开源固件,3D打印固件有很多,Marlin最为健全和强大,当然相对也会复杂一些.使用Gcode控制爱.Gcode是数控机床等工控控制使用范围较广 ...
- Unity自己主动打包工具
最開始有写打包工具的想法,是由于看到<啪啪三国>王伟峰分享的一张图,他们有一个专门的"工具程序猿"开发各种工具. (ps:说起来这个王伟峰和他的创始团队成员,曾经跟我是 ...
- HDU 6138 Fleet of the Eternal Throne 后缀数组 + 二分
Fleet of the Eternal Throne Problem Description > The Eternal Fleet was built many centuries ago ...
- STM32低功耗模式与烟雾报警器触发信号电路设计
1.STM32的3种低功耗模式 STM32有3种低功耗模式,分别是睡眠模式.停机模式和待机模式. 2.STM32在不同模式下的电流消耗 a.工作模式 消耗电流在27mA至36mA之间. b.睡眠模式 ...
- 命令行唤起xcode模拟器
1.IOS模拟器列表获取命令 xcrun instruments -s 2.IOS启动模拟器命令 xcrun instruments -w "iPhone 8 (12.1)"
- vue-router-h5-history
vue-router的HTML5 History 模式,这种模式充分利用 history.pushState API 来完成 URL 跳转而无须重新加载页面. const router = new V ...
- HDU2089 不要62 —— 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2089 不要62 Time Limit: 1000/1000 MS (Java/Others) M ...