Ural 1960 Palindromes and Super Abilities
Palindromes and Super Abilities
This problem will be judged on Ural. Original ID: 1960
64-bit integer IO format: %lld Java class name: (Any)
Input
Output
Sample Input
aba
Sample Output
1 2 3
Source
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct PalindromicTree{
int fail[maxn],len[maxn],son[maxn][];
int tot,last,n;
char s[maxn];
int newnode(int slen = ){
memset(son[tot],,sizeof son[tot]);
len[tot] = slen;
return tot++;
}
void init(){
n = tot = last = ;
newnode();
newnode(-);
fail[] = fail[] = ;
s[n] = -;
}
int getFail(int x){
while(s[n - len[x] - ] != s[n]) x = fail[x];
return x;
}
void extend(int c){
s[++n] = c;
int cur = getFail(last);
if(!son[cur][c]){
int x = newnode(len[cur] + );
fail[x] = son[getFail(fail[cur])][c];
son[cur][c] = x;
}
last = son[cur][c];
}
}pt;
char str[maxn];
int main(){
while(~scanf("%s",str)){
pt.init();
bool flag = false;
for(int i = ; str[i]; ++i){
pt.extend(str[i] - 'a');
if(flag) putchar(' ');
printf("%d",pt.tot - );
flag = true;
}
putchar('\n');
}
return ;
}
Ural 1960 Palindromes and Super Abilities的更多相关文章
- 回文树(回文自动机) - URAL 1960 Palindromes and Super Abilities
Palindromes and Super Abilities Problem's Link: http://acm.timus.ru/problem.aspx?space=1&num=19 ...
- URAL 2040 Palindromes and Super Abilities 2(回文树)
Palindromes and Super Abilities 2 Time Limit: 1MS Memory Limit: 102400KB 64bit IO Format: %I64d ...
- URAL 2040 Palindromes and Super Abilities 2 (回文自动机)
Palindromes and Super Abilities 2 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/E Descr ...
- Ural 2040. Palindromes and Super Abilities 2 回文自动机
2040. Palindromes and Super Abilities 2 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2040 ...
- URAL 2040 Palindromes and Super Abilities 2
Palindromes and Super Abilities 2Time Limit: 500MS Memory Limit: 102400KB 64bit IO Format: %I64d &am ...
- 【URAL】1960. Palindromes and Super Abilities
http://acm.timus.ru/problem.aspx?space=1&num=1960 题意:给一个串s,要求输出所有的s[0]~s[i],i<|s|的回文串数目.(|s|& ...
- 回文树1960. Palindromes and Super Abilities
Bryce1010模板 http://acm.timus.ru/problem.aspx?space=1&num=1960 #include <bits/stdc++.h> usi ...
- URAL1960 Palindromes and Super Abilities
After solving seven problems on Timus Online Judge with a word “palindrome” in the problem name, Mis ...
- Ural2040:Palindromes and Super Abilities(离线&manecher算法)
Dima adds letters s1, …, sn one by one to the end of a word. After each letter, he asks Misha to tel ...
随机推荐
- h5-26-web本地存储
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- windows clone 迁移数据库
windows clone 迁移数据库可行.(c 盘底成复制)
- .net core区域设置方式
在Startup中配置 默认路由是这个,并不包含区域路由 routes.MapRoute( name: "default", template: "{controller ...
- poj1190 生日蛋糕
题意: 要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1 <= i <= M)层蛋糕是半径为Ri, 高度为Hi的圆柱.当i < M时,要求Ri > ...
- obj.style 和currentstyle 等区别
版权声明:本文为博主原创文章,未经博主允许不得转载. 获取样式 obj.style 和currentstyle 等区别 obj.style只能获得内嵌样式(inline Style)就是写 ...
- Android原生系统API自带dp、px、sp单位转换
Android系统中自带的Api中可以使用TypedValue进行单位转换 1,调用系统api转换单位 // 获得转换后的px值 float pxDimension = TypedValue.appl ...
- Android Learning Note -- AsyncTask浅尝
AsyncTask 实现原理 AsyncTask是Android提供的轻量级异步类,可以直接继承AsyncTask在类中实现异步操作,并提供接口反馈当前的异步执行程度(通过接口实现UI进度更新),最后 ...
- Junit测试集锦
Junit测试集锦 前言: 一个程序从设计很好的状态开始,随着新的功能不断地加入,程序逐渐地失去了原有的结构,最终变成了一团乱麻.所以在开发过程中,对于程序员来说,测试是非常重要的.言归正传,开始Ju ...
- 小知识~VS2012的xamarin加载失败解决
1 由于Nuget版本过低导致的,工具->扩展和更新->在线更新->对nuget程序包程序器进行升级即可 错误代码: 错误 4 错误: 缺少来自类“NuGet.Visua ...
- Qt学习笔记12:基本会话框4——总结
文件对话框静态函数 QString QFileDialog::getOpenFileName{ QWidget *parent = 0; //标准文件对话框的父窗口 const QString &am ...