种种原因,第五周的div2还没做完,所以先把这个做完。(solved)
学习manacher(马拉车)算法,n ^2解决HDU 2859
update on 2019/2/22/23:51
自闭了。好像比我想象的要困难许多啊,明天补一下吧。
update on 2019/2/25/19:37
感觉还是不会,置顶占坑。
update on 2019/3/1/15:49
今天中午好像知道这个怎么做了。
1,求出每个位置向左下和右上延伸的最大长度,这个用Manacher可以n ^ 2完成
2,现在问题变成了,对于副对角线方向的区间,求出最大的区间,使min(区间长度,区间最小值)最大,这个two pointers即可轻松完成。
现在看上去是没有什么问题的,等我晚上代码实现一下。
update on 2019/3/1/23:41
dbq我又想简单了,但是我感觉已经很接近了,这个思路大致上是不错的,但是有一些细节有待考虑。
continuing……
先贴一个fake solution,方便我随时修改。
//My Conquest Is the Sea of Stars.
#pragma GCC diagnostic error "-std=c++11"
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define endl "\n"
#define fi first
#define se second
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lowbit(x) x & (-x)
#define PII pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(__typeof(b) i = a; i <= (b); i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i >= (b); i--)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e3 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
char G[maxn][maxn];
int rad[maxn][maxn];
char s[maxn*2];
int p[maxn*2];
int n;
void Manacher(int x, int y){
int tx = x, ty = y;
int len = n - abs(x - y) - 1;
int l = 0;
s[l++] = '$';
s[l++] = '#';
rep(i, 1, len){
s[l++] = G[x++][y++];
s[l++] = '#';
}
int mx = 0, id = 0;
rep(i, 0, l - 1){
p[i] = mx > i ? min(p[2*id-i], mx - i) : 1;
while(s[i+p[i]] == s[i-p[i]]) p[i]++;
if(i + p[i] > mx){
mx = i + p[i];
id = i;
}
}
for(int i = 2; i < l; i += 2){
rad[tx++][ty++] = p[i] - 1;
}
}
int main()
{
scanf("%d", &n);
rep(i, 1, n) rep(j, 1, n) scanf(" %c", &G[i][j]);
rep(j, 1, n){
fill(p, p + 2 * n + 2, 0);
Manacher(1, j);
}
rep(i, 2, n){
fill(p, p + 2 * n + 2, 0);
Manacher(i, 1);
}
rep(i, 1, n){
rep(j, 1, n){
printf("%d ", rad[i][j]);
}
puts("");
}
return 0;
}
update on 2019/4/17 18:16
我现在觉得这个好像是不可做的?
先不管了吧,取消置顶等我有一天遇到了或者想起来了再说吧。每天看着一个我不会的并且unsolved的问题有点难受。