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 ...
随机推荐
- linux cut sort wc sed>vi awk (文本处理)
cut: 显示切割的行数据 -f: 选择显示的列 (1: 显示第一列; 1,3: 显示第一列.第三列; 1-3: 显示第一列到第三列) -s: 不显示没有分隔符的行 -d: 自定义分隔符(' '空格 ...
- 2018-2019-2-20175225 实验四《Android开发基础》实验报告
一.实验报告封面 课程:Java程序设计 班级:1752班 姓名:张元瑞 学号:20175225 指导教师:娄嘉鹏 实验日期:2019年5月14日 实验时间:13:45 - 21:00 实验序号:实验 ...
- NLP大赛冠军总结:300万知乎多标签文本分类任务(附深度学习源码)
NLP大赛冠军总结:300万知乎多标签文本分类任务(附深度学习源码) 七月,酷暑难耐,认识的几位同学参加知乎看山杯,均取得不错的排名.当时天池AI医疗大赛初赛结束,官方正在为复赛进行平台调 ...
- Maven中的dependency详解
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> & ...
- AJAX向Django后端提交POST请求
一.ajax登录示例 二.CSRF跨站请求伪造 方式一 方式二 方式三 方式四 一.ajax登录示例 urls.py from django.conf.urls import url from dja ...
- BDD Cucumber 实战
cucumber cucumber 是一个用于执行 BDD 的自动化测试工具. 用户指南 创建 Spring Boot 项目并引入依赖 <?xml version="1.0" ...
- Vue创建局部组件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- windows的VMWare下NAT共享无线方式上网的配置
1,本文参看: https://blog.51cto.com/13648313/2095288 VMware安装最新版CentOS7图文教程 https://blog.csdn.net/q215879 ...
- 【命令汇总】XSS payload 速查表
日期:2019-05-15 14:06:21 作者:Bay0net 介绍:收集并且可用的一些 XSS payload,网上的速查表很多,但是测试了下很多 payload 的不可用,这里都是自己能用的 ...
- div动画旋转效果
animation: spin 10s linear infinite;