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 ...
随机推荐
- freertos之特点
主要特点:协程(co-routine):任务间的中断通信机制 支持可抢占式/协作式任务调度 .FreeRTOS-MPU 内核对象可以动态或静态分配 ...
- 玩ztree的一段代码
<!DOCTYPE HTML> <html lang="zh" xmlns:th="http://www.thymeleaf.org"> ...
- Git-merge & rebase(变基)
在 Git 中整合来自不同分支的修改主要有两种方法:merge 以及 rebase. merge: merge有两种方法,fast-forward(快速合并)和three-way merge(三方合并 ...
- 阻止JEB 1.5频繁弹窗的办法
偶尔才用一次的JEB, 出现 “Controller没有响应或者无法访问, JEB即将终止.” 也懒得去逆了.直接用ProcessHacker找到对应的线程挂起即可.当然这只是临时的办法..我也只是临 ...
- HEVC标准介绍+论文阅读笔记
脱离视频编解码.投入计算机视觉一年,这个博客也歇业一年,最近偷些时间回顾一下编解码,毕竟花费了整个研一的时间(虽然这一年基本上在上课). 之前写过几篇H.264标准的几篇介绍文章,详见:http:// ...
- 如何用Chrome自带的截屏功能截取超过一个屏幕的网页
提升程序员工作效率的工具/技巧推荐系列 推荐一个功能强大的文件搜索工具SearchMyFiles 介绍一个好用的免费流程图和UML绘制软件-Diagram Designer 介绍Windows任务管理 ...
- 新时代web组件开发标准
VUE框架,则是遵行了这个标准. 1.html文件 <!DOCTYPE html><html><head lang="en"> <meta ...
- qobject_cast
void QLadderDiagramItem::GetMainForm(DoType sourceType){ for each (QWidget *w in qApp->topLevelWi ...
- Perl中 qw 是 “quoted Word” 或是 “quoted by whitespace”的简写
Perl中 qw 是 “quoted Word” 或是 “quoted by whitespace”的简写 eg: @strict_pragma = qw ( a b c);
- pm2 start命令进阶详解
在node的世界里面,并不存在nginx或者apache,甚至tomcat这种东东.一个node,本身就用几行代码,就可以启动个server进程,监听个端口,为大家提供web服务.这和传统的网站代码的 ...