POJ3690:Constellations——题解
http://poj.org/problem?id=3690
题目大意:给一个图和几个子图,判断有多少种子图在原图出现过。
——————————————————————
二维哈希即可,操作看代码,我觉得蛮好看的。
注意这题恶心的时限。
pow预处理能少时间,读入字符用getchar不然会TLE。
用multiset查找然后再一个个erase即可,这样set前后size的差值即是答案。
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<set>
using namespace std;
typedef unsigned long long ll;
const int N=;
const int M=;
const int P=;
const int Q=;
const ll b=;
const ll w=1e8+;
ll ha0[N][M];
ll ha1[P][Q];
ll qpow[][P];
inline ll tn(char ch){
if(ch=='')return ;
return ;
}
void init(){
qpow[][]=qpow[][]=;
for(int i=;i<P;i++){
qpow[][i]=qpow[][i-]*b;
qpow[][i]=qpow[][i-]*w;
}
return;
}
int main(){
init();
int n,m,t,p,q,casenum=;;
while(cin>>n>>m>>t>>p>>q){
if(n+m+t+p+q==)break;
multiset<ll>app;
casenum++;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
char ch=getchar();
while(ch==' '||ch=='\n')ch=getchar();
ha0[i][j]=ha0[i][j-]*b+tn(ch);
}
}
for(int j=;j<=m;j++){
for(int i=;i<=n;i++){
ha0[i][j]+=ha0[i-][j]*w;
}
}
for(int k=;k<=t;k++){
for(int i=;i<=p;i++){
for(int j=;j<=q;j++){
char ch=getchar();
while(ch==' '||ch=='\n')ch=getchar();
ha1[i][j]=ha1[i][j-]*b+tn(ch);
}
}
for(int j=;j<=q;j++){
for(int i=;i<=p;i++){
ha1[i][j]+=ha1[i-][j]*w;
}
}
app.insert(ha1[p][q]);
}
for(int i=p;i<=n;i++){
for(int j=q;j<=m;j++){
int si=i-p,sj=j-q;
app.erase(ha0[i][j]-ha0[si][j]*qpow[][p]-ha0[i][sj]*qpow[][q]+ha0[si][sj]*qpow[][p]*qpow[][q]);
}
}
printf("Case %d: %d\n",casenum,t-(int)app.size());
}
return ;
}
POJ3690:Constellations——题解的更多相关文章
- POJ3690 Constellations 【KMP】
Constellations Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5044 Accepted: 983 Des ...
- POJ3690:Constellations(二维哈希)
Constellations Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6822 Accepted: 1382 题目 ...
- POJ3690 Constellations
嘟嘟嘟 哈希 刚开始我一直在想二维哈希,但发现如果还是按行列枚举的话会破坏子矩阵的性质.也就是说,这个哈希只能维护一维的子区间的哈希值. 所以我就开了个二维数组\(has_{i, j}\)表示原矩阵\ ...
- 【poj3690】Constellations 哈希
传送门 题目分析 考虑将大矩阵的每个1*q矩阵哈希值求出,然后让小矩阵的第一行在大矩阵中找,如果找到,并且能匹配所有行则出现过.否则没出现过. 在初始化1*q矩阵时可以进行优化:假设该行为123456 ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
随机推荐
- 「日常训练」School Marks(Codeforces Round 301 Div.2 B)
题意与分析(CodeForces 540B) 题意大概是这样的,有一个考试鬼才能够随心所欲的控制自己的考试分数,但是有两个限制,第一总分不能超过一个数,不然就会被班里学生群嘲:第二分数的中位数(科目数 ...
- 【白书训练指南】(UVa10755)Garbage Heap
先po代码,之后把我那几个不太明了的知识点讲讲,巩固以下.三维的扫描线算法想要掌握还真是有一定的难度的. 代码 #include <iostream> #include <cstri ...
- HTML <head>里面的标签
<head> 中的标签可以引用脚本.指示浏览器在哪里找到样式表.提供元信息等等. 下面这些标签可用在 head 部分:<base>, <link>, <met ...
- 用最简单的MVC模式输出内容
MVC是模型(model)-视图(view)-控制器(controller)的缩写,它的作用是使代码分离,可维护性高.重用性高 编写Model层: <?php class model{ publ ...
- [JSON].remove( keyPath )
语法:[JSON].remove( keyPath ) 返回:无 说明:移除指定路径的键 示例: Set jsonObj = toJson("{div:{'#text-1': 'is tex ...
- [ Continuously Update ] The Paper List of Image / Video Captioning
Papers Published in 2018 Convolutional Image Captioning - Jyoti Aneja et al., CVPR 2018 - [ Paper Re ...
- 使用eclipse创建maven项目出现的一个问题
错误信息 This error occurs when you employ a plugin that Maven could not download. Possible causes for t ...
- Java实验二实验报告:java面向对象程序设计
java实验二实验报告 实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解设计模式 实验 ...
- 有关c#的学习笔记整理与心得
[ 塔 · 第 一 条 约 定 ] 整理c#:Array Arraylist List Hashtable Dictionary Stack Queue等 Array 的容量是固定的,而 ArrayL ...
- 软工实践Alpha冲刺(3/10)
队名:我头发呢队 组长博客 作业博客 杰(组长) 过去两天完成了哪些任务 继续翻阅Google Material Design 2的官方文档 接下来的计划 音源爬取 还剩下哪些任务 app开发 燃尽图 ...