Misha and Palindrome Degree】的更多相关文章

Misha and Palindrome Degree 题目链接:http://codeforces.com/problemset/problem/501/E 贪心 如果区间[L,R]满足条件,那么区间[L',R'](L'<=L,R<=R')必然满足条件,所以只需要找到满足条件的最小区间即可.首先去除两边相同的区间,剩下的区间为[l,r],因为区间[l,r]的两端不相同,所以要找的最小区间必然包含区间[l,r]的最左端或者最右端.观察到所选区间内的同种元素个数必需大于等于整个区间内同种元素的个…
大意: 给定字符串, 求多少个区间重排后能使原串为回文串. 先特判掉特殊情况, 对于两侧已经相等的位置之间可以任意组合, 并且区间两端点至少有一个在两侧相等的位置处, 对左右两种情况分别求出即可. #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <…
题目链接: http://codeforces.com/problemset/problem/7/D D. Palindrome Degree time limit per test1 secondmemory limit per test256 megabytes 问题描述 String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length…
D. Palindrome Degree 题目连接: http://www.codeforces.com/contest/7/problem/D Description String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length are (k - 1)-palindromes. By definition, any string (ev…
个人心得:这题就是要确定是否为回文串,朴素算法会超时,所以想到用哈希,哈希从左到右和从右到左的key值一样就一定是回文串, 那么问题来了,正向还能保证一遍遍历,逆向呢,卡住我了,后面发现网上大神的秦九韶算法用上了,厉害了. 关于哈希,这题用的是最简单的哈希思想,就是用M取合理的素数,这题取得是3, 然后正向就是 a+=a*M+ch[i].逆向用秦九韶可以在循环的时候算出来, 举个例子比如三个值1,2,3. 假如逆向开始 则 (((0+s[3])*M+s[2])*M+s[1]);化简就等于s[1]…
题目链接:http://codeforces.com/contest/7/problem/D D. Palindrome Degree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output String s of length n is called k-palindrome, if it is a palindrome itself…
D. Palindrome Degree time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length  are(k - …
manacher+dp.其实理解manacher就可以解了,大水题,dp就是dp[i]=dp[i>>1]+1如何满足k-palindrome条件. /* 7D */ #include <iostream> #include <string> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #inc…
最近接触了一点字符串算法,其实也就是一个简单的最大回文串算法,给定字符串s,求出最大字符串长度. 算法是这样的, 用'#'将s字符串中的每个字符分隔,比如s = "aba",分割后变成#a#b#a#,然后利用下面的算法: pre: mx ←0    for i: = 1 to n-1         if(mx>i)           p[i] = min(p[2*id-i], mx-i)         else p[i] = 1        while(str[i+p[i…
题目链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #include<string> #include<stdlib.h> #include<a…