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 只做出来四道比较水的题目,还需要加强中等题的训练 ...
随机推荐
- MyBatis-MBG(MyBatis Generator)
1.添加jar包 <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>m ...
- Postman 高级用法指南
Postman是一款强大的API接口测试工具,有许多不容易发现的好用的功能,下面简单介绍其中一部分功能.详细内容可以参考文档,官方还有视频教程,非常方便入手.后续本博客会持续提供一些Postman使用 ...
- Python全栈 进阶(进阶内容都在这了)
原文地址 https://yq.aliyun.com/articles/632754?spm=a2c4e.11155435.0.0.23eb3312feB6dG ................... ...
- 【带 josn参数的测法】
遇到json 参数的情况这样写 ,否则就会报错 cod 415 nocookie post请求 ,","email":"beihe@163.com&quo ...
- java代码读取yarn聚合目录日志
可以直接使用org.apache.hadoop.yarn.client.cli.LogsCLI(yarn logs -applicationId)中的main方法逻辑,如 public static ...
- ElasticSearch 论坛搜索查询语句
概述 研究论坛搜索如何综合时间和TF/IDF权重. 自定义权重计算的效率问题 数据结构 假设有一个论坛的搜索 字段包括: subject:标题 message:内容 dateline:发布时间 tag ...
- Python3.5 Keras-Theano(含其他库)windows 安装环境
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.2.0-Windows-x86.execonda --version ...
- nodejs promise深度解析
Promise本质上是一个容器,内部有一个执行函数,当promise对象New出来的时候,内部包裹的函数立即执行. V8引擎会将resolve和projeccted两个函数传递进来,resolved含 ...
- Python3 Tkinter-Pack
1.创建 from tkinter import * root=Tk() print(root.pack_slaves()) Label(root,text='pack').pack() print( ...
- Kali信息收集工具-dimtry
帮助文档 -s和-e参数需要用到google搜索 1.获取whois主机ip信息 2.扫描端口,根据banner信息判断服务