POJ 3690 Constellations (哈希)】的更多相关文章

题意:给定上一n*m的矩阵,然后的t个p*q的小矩阵,问你匹配不上的有多少个. 析:可以直接用哈希,也可以用AC自动机解决. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream>…
原题 在大矩阵里找有几个小矩阵出现过,多组数据 将t个矩阵hash值放入multiset,再把大矩阵中每个hash值从multiset里扔出去,这样最后剩在multiset里的值就是没有找到的小矩阵,答案就是t-size了. 矩阵hash: a[i][j]为以i,j为右下角的长为p,宽为q的hash值. 先处理横行的hash,然后再把横行的hash值hash,这样就得到了矩阵的hash值.(注意行和列的base要不一样,不然很容易WA) #include<cstdio> #include<…
Constellations Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5923   Accepted: 1164 Description The starry sky in the summer night is one of the most beautiful things on this planet. People imagine that some groups of stars in the sky f…
题目链接: http://poj.org/problem?id=2002 #include <stdio.h> #include <string.h> ; struct Hash_table { int x, y; struct Hash_table *next; }*Hash[prime]; void Hash_insert(int x, int y) { int key = (x + y) % prime; if(Hash[key] == NULL) { Hash[key] =…
传送门 题目分析 考虑将大矩阵的每个1*q矩阵哈希值求出,然后让小矩阵的第一行在大矩阵中找,如果找到,并且能匹配所有行则出现过.否则没出现过. 在初始化1*q矩阵时可以进行优化:假设该行为123456,要求1*5的矩阵哈希值,可以先暴力求出1~5,为 $1 * H^4 + 2 * H^3 + 3 * H^2 + 4 * H + 5$,现在要删除1添加6:变为$2 * H^4 + 3 * H^3 + 4 * H^2 + 5 * H + 6$,也就是先减去1的哈希值乘以$H^{len - 1}$,然…
Long Long Message #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <queue> #include <stack> #include <cmath> #include <map> #include <string&…
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj3295) (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996) 二.图算法:…
POJ 1002 - 487-3279(基础)http://acm.pku.edu.cn/JudgeOnline/problem?id=1002题意:略解法:二叉查找数,map,快排... POJ 1200 - Crazy Search(基础)http://acm.pku.edu.cn/JudgeOnline/problem?id=1200题意:找出不相同的子串数量,字母表大小和子串长度会给定,这题很推荐hash入门者一做解法:hash(建议karp-rabin) POJ 1204 - Word…
Constellations Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6822   Accepted: 1382 题目链接:http://poj.org/problem?id=3690 Description: The starry sky in the summer night is one of the most beautiful things on this planet. People imagine t…
题目链接:http://poj.org/problem?id=1635 题目大意:给你两棵树的dfs描述串,从根节点出发,0代表向深搜,1代表回溯. 我刚开始自己设计了哈希函数,不知道为什么有问题....参考了http://www.cnblogs.com/jackiesteed/articles/2065307.html,他的就是对的..我也不知道为什么.. #include <cstdio> #include <algorithm> #include <cstring>…