题目链接:hdu 4941 Magical Forest
题目大意:给定N,M和K,表示在一个N*M的棋盘上有K个棋子,给出K个棋子的位置和值,然后是Q次操作,对应的是:
1 a b :交换a和b两行2 a b : 交换a和b两列3 a b :查询a b这个位置上棋子的值,没有棋子的话输出0
解题思路:一开始X[i]=i,X[j]=j,如果需要交换i和j,那么就令X[i]=j,X...
分类:
其他好文 时间:
2014-08-12 18:59:04
阅读次数:
204
在linux的shell中我们习惯使用case语句来做分支处理,然而Python中却省略了这个函数,经过多方查找,发现其实case语句在C语言中是通过查对应的hash表,来进行跳转的。在Python中我们可以通过三种方法来实现这种功能。1、字典;2、lambda;3、switch类。1、字典dictCase={‘case1..
分类:
编程语言 时间:
2014-08-12 17:41:15
阅读次数:
487
通过hash表。stl不存在hash容器,自己创建一个,共有256个字符,很简单就创建出来了
代码:
#include
//第一个出现一次的字符
using namespace std;
char findChar(char * pString){
if(pString == NULL)
return '\0';
const int tableSize = 256;
unsig...
分类:
其他好文 时间:
2014-08-12 13:37:44
阅读次数:
135
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