Codeforces Round #427 (Div. 2) - D
题目链接:http://codeforces.com/contest/835/problem/D
题意:给定一个字符串,定义kth回文是左半部分等于右半部分,并且左半部分和右半部分都是(k-1)th回文。 只要是回文字串都是1th回文。 对于1<=k<=strlen(s),输出kth回文的数量。
思路:预处理出每个子串是否是回文。然后len^2枚举区间,如果s[i][j]是回文的话,继续枚举左半部分s[i][i+(j-i+1)/2-1]是否是回文,是的话再继续枚举左半部分然后顺便统计答案即可。 对于统计贡献,假设s[i][j]连续枚举了x次左半部分都是回文,第x+1次的左半部分不是回文,则说明s[i][j]是xth回文, s[i][j]的左半部分是x-1th回文....相当于把(1~x)th贡献+1,代码里是逆着算贡献即xth回文算到1th中,但是并不影响最后对答案的贡献
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<time.h>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long int LL;
const int MAXN = + ;
const int INF = 1e9;
const int mod = 1e9 + ;
char str[MAXN];
LL ans[MAXN];
bool isPalind[MAXN][MAXN];
void Make_Palind(int len){
for (int i = ; i < len; i++) {
int l = i, r = i;
for (int l = i, r = i; l >= && r < len&&str[l] == str[r]; l--, r++){ //奇长度回文
isPalind[l][r] = true;
}
for (int l = i, r = i + ; l >= && r < len&&str[l] == str[r]; l--, r++){ //偶长度回文
isPalind[l][r] = true;
}
}
} int main(){
#ifdef kirito
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
while (~scanf("%s", str)){
int len = strlen(str);
memset(ans, , sizeof(ans));
memset(isPalind, false, sizeof(isPalind));
Make_Palind(len);
for (int i = ; i < len; i++){
for (int j = i; j < len; j++){
for (int l = i, r = j, k = ; l >= && r < len && r >= l && isPalind[l][r]; r = l + (r - l + ) / - , k++){
ans[k]++;
}
}
}
for (int i = ; i <= len; i++){
printf("%lld%c", ans[i], (i == len ? '\n' : ' '));
}
}
return ;
}
Codeforces Round #427 (Div. 2) - D的更多相关文章
- CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)
s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...
- CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)
证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...
- Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...
- Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...
- Codeforces Round #427 (Div. 2) Problem A Key races (Codeforces 835 A)
Two boys decided to compete in text typing on the site "Key races". During the competition ...
- Codeforces Round #427 (Div. 2) B. The number on the board
引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...
- Codeforces Round #427 (Div. 2)—A,B,C,D题
A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...
- Codeforces Round #427 (Div. 2)——ABCD
http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...
- 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics
[Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...
- 【Codeforces Round #427 (Div. 2) A】Key races
[Link]:http://codeforces.com/contest/835/problem/A [Description] [Solution] 傻逼题. [NumberOf WA] [Revi ...
随机推荐
- 使用注解装配Bean
注解@Component代表Spring Ioc 会把 这个类扫描生产Bean 实例,而其中 value属性代表这个类在Spring 中的id,这就相当于XML方式定义的Bean 的 id 现在有了 ...
- jdk环境配置(windows版)
JAVA_HOME C:\Program Files\Java\jdk1.7.0_80 Path %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin; CLASSPATH .;%J ...
- 关闭layer.open打开的页面
window.parent.location.reload(); //刷新父页面 var index = parent.layer.getFrameIndex(window.name); //获取窗口 ...
- RAC_单实例_DG 关于两端创建表空间数据文件路径不一致的问题注意点
RAC_单实例_DG 关于两端创建表空间数据文件路径不一致的问题注意点 主库SYS@orcl1>show parameter db_file_name_convert NAME TYPE VAL ...
- 通过nginx访问本地图片
listen 80; server_name image.demo.com; #charset koi8-r; #access_log logs/host.access.log main; locat ...
- 阶段3 1.Mybatis_01.Mybatis课程介绍及环境搭建_03.jdbc操作数据库的问题分析
分析一段代码,传统的jdbc的功能,最终要实现的功能就是sql语句.
- 禁止SYS和SYSTEM用户远程登录Oracle oracle的sys和system默认密码
alter system set remote_login_passwordfile=none scope=spfile; system默认:manager sys默认:change_on_insta ...
- 【Windows Server存储】windows文件系统
windows文件系统 弹性文件系统(ReFS) 无检查磁盘,Windows 8或Windows Server 2012以上运行. 参考资料表明,这是一个失败的文件系统,以后将不会商用. 参考资料:h ...
- centos7下执行firewall-cmd显示ImportError: No module named 'gi'
centos7 安装tomcat 及问题处理(No module named 'gi')(Job for firewalld.service failed because the control) 2 ...
- 红帽学习笔记[RHCSA] 第一课[Shell、基础知识]
关于Shell Shell是什么 Shell是系统的用户界面,提供了用户与内核进行交互操作的一种接口.它接收用户输入的命令并把它送入内核中执行. bash shell是大多数Linux的缺省shell ...