Problem Description
Let's play a card game called Gap.
You have 28 cards labeled with two-digit numbers. The first digit (from 1 to 4) represents the suit of the card, and the second digit (from 1 ...
分类:
其他好文 时间:
2014-08-12 10:24:14
阅读次数:
379
bnu36907 Subpalindromes
字符串hash+线段树
题意:给一个字符串(
1)将指定位置的字符改为c
2)询问l-r的子串,是否是回文串。
解法 :区间维护pl和pr,表示从左到右的hash和从右到左的hash,然后在up和query中合并区间,最后判断pl和pr是否相等即可。
#include
#include
#include
#include
#inc...
分类:
其他好文 时间:
2014-08-11 21:29:52
阅读次数:
301
http://poj.org/problem?id=2549
维基百科有3Sum算法:https://en.wikipedia.org/wiki/3SUM
sort(S);
for i=0 to n-3 do
a = S[i];
k = i+1;
l = n-1;
while (k<l) do
b = S[k];
c = ...
分类:
其他好文 时间:
2014-08-11 21:23:53
阅读次数:
356
http://poj.org/problem?id=2417
A^x = B(mod C),已知A,B,C,求x。
这里C是素数,可以用普通的baby_step。
在寻找最小的x的过程中,将x设为i*M+j。从而原始变为A^M^i * A^j = B(mod C),D = A^M,那么D^i * A^j = B(mod C ),
预先将A^j存入hash表中,然后枚举i(0~M-1...
分类:
其他好文 时间:
2014-08-11 21:19:32
阅读次数:
229
转自:江南烟雨IP哈希初始化IP哈希的初始化函数ngx_http_upstream_init_ip_hash(ngx_http_upstream_ip_hash_module.c):static ngx_int_tngx_http_upstream_init_ip_hash(ngx_conf_t *...
分类:
其他好文 时间:
2014-08-11 21:00:42
阅读次数:
325
http://poj.org/problem?id=3690
UVA还有一道也是这样的题,LRJ给的算法是AC自动机----我还没写过,今天用HASH搞了这道题
思路很清晰,但是处理起来还因为HASH函数写混WA了几次。。。
文本矩阵n*m T个匹配矩阵p*q
思路:
1、把每一行处理出长为q的hash值
2、对于1中得到的p个哈希值在算一次哈希,这样就把一个矩阵用一个hash值...
分类:
其他好文 时间:
2014-08-11 17:49:02
阅读次数:
205
题目:http://poj.org/problem?id=1200
题意:给一个字符串,给定n和nc,字符串里最多有nc个不同的字符,问长度为n的不同子串最多有几个
和上一篇现场赛那个一样,也是难在判重处理不好会超时
方法:将长度为n的子串映射为一个nc进制的数,开一个大数组,判断是否重复
#include
#include
#include
#include
#include
...
分类:
其他好文 时间:
2014-08-11 15:13:42
阅读次数:
218
http://acm.hdu.edu.cn/showproblem.php?pid=4821
昨晚卡了很久,开始TLE,然后优化了之后,因为几个地方变量写混,一直狂WA,搞得我昨晚都失眠了,,,
这几次hash军写错的变量--tmp=(j==m-1)?ah[j]:(ah[j]-ah[j-m]*base[m]); 外层循环变量是i,我写的字符串hash的几题都写成tmp=(i==0)?ah[j...
分类:
其他好文 时间:
2014-08-11 10:10:42
阅读次数:
245
代码如下(主要是通过设置Location的hash属性):无标题文档页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容页面内容...
分类:
Web程序 时间:
2014-08-11 10:02:31
阅读次数:
188
解题报告
题意:
一根长度8000的线段上染色,求染完之后,每个颜色在线段上有多少个间断的区间。
思路:
区间问题用线段树,成段的更新区间,最后把所有的区间下压到叶子结点,统计叶子结点的颜色。
#include
#include
#include
using namespace std;
int lz[32000],_hash[10000],color[10000],cnt;
v...
分类:
其他好文 时间:
2014-08-11 06:19:21
阅读次数:
258