Palindrome Degree(hash的思想题)】的更多相关文章

个人心得:这题就是要确定是否为回文串,朴素算法会超时,所以想到用哈希,哈希从左到右和从右到左的key值一样就一定是回文串, 那么问题来了,正向还能保证一遍遍历,逆向呢,卡住我了,后面发现网上大神的秦九韶算法用上了,厉害了. 关于哈希,这题用的是最简单的哈希思想,就是用M取合理的素数,这题取得是3, 然后正向就是 a+=a*M+ch[i].逆向用秦九韶可以在循环的时候算出来, 举个例子比如三个值1,2,3. 假如逆向开始 则 (((0+s[3])*M+s[2])*M+s[1]);化简就等于s[1]…
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…
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 - …
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]的最左端或者最右端.观察到所选区间内的同种元素个数必需大于等于整个区间内同种元素的个…
题目链接: 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…
题目链接: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…
学了kmp之后又学了hash来搞字符串.这东西很巧妙,且听娓娓道来. 这题的题意是:一个字符串如果是回文的,那么k值加1,如果前一半的串也是回文,k值再加1,以此类推,算出其k值.打个比方abaaba,k值为3,abaxxaba,k值为1.现在,给出一个串,让你求这个串的所有前缀(包括本身)的k值的和. 如果考虑马拉车,那么先预处理出每个地方的最长回文长度,然后不断的截断,如果子串的回文长度大于其回文长度,那么k值加1,这样即可.但是马拉车写起来比较繁琐,没有模板我也没法手写. 这里提供hash…
题目链接:点击打开链接 #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…
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298840.html   ---by 墨染之樱花 题目链接:http://poj.org/problem?id=1077 题目描述:民间流传的推15游戏,不过这里简化为3*3,也就是八数码问题,‘x’表示空位.与AOJ0121的“Seven Puzzle”类似. 思路:没什么特别的,构造字符串队列,爆搜一下.注意Hash函数,哈得好就哈哈,哈得不好就只能呵呵了...我的hash函数是∑((s…
LINK1 LINK2 题目大意 让你在一个大小为\(n*m\)的矩阵中找大小是\(x*y\)的矩阵的出现次数 思路1:Hash hash思路及其傻逼 你把一维情况扩展一下 一维是一个bas,那你二维就用两个bas好了 对一个在\((i,j)\)的字符,令他的hash值是\(c_{i,j}*bas1^i*bas2^j\) 然后算出矩阵hash值乘上差量判断就做完了 70ms //Author: dream_maker #include<bits/stdc++.h> using namespac…