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 只做出来四道比较水的题目,还需要加强中等题的训练 ...
随机推荐
- Spark性能优化--数据倾斜调优与shuffle调优
一.数据倾斜发生的原理 原理:在进行shuffle的时候,必须将各个节点上相同的key拉取到某个节点上的一个task来进行处理,比如按照key进行聚合或join等操作.此时如果某个key对应的数据量特 ...
- 微信小程序—day04
元素水平+垂直居中 昨天的用户页的用户头像,是根据已知的像素大小,设置固定的值,达到居中的效果. 今日切换机型进行适配,发现对不同尺寸大小的屏幕不匹配.所以对wxss进行修改,真正达到水平+垂直居中. ...
- lesson 24 A skeleton in the cupboard
lesson 24 A skeleton in the cupboard conceal sth from sb 对某人隐藏某事 He conceals his girlfriend from his ...
- Oracle存储过程练习题
1.1.创建一个过程,能向dept表中添加一个新记录.(in参数) 创建过程 create or replace procedure insert_dept ( num_dept in number, ...
- linux学习总结----mongoDB总结
dbhelper.py 用户登录和注册(加密算法) 加密导包 import hashlib 或者使用Md5 加密 MongoDB ->JSON service mysql start servi ...
- 配置vConsole调试console
1.使用 npm 安装: npm install vconsole 再使用webpack,然后js代码中 import VConsole from 'vconsole/dist/vconsole.mi ...
- python selenium 使用htmlunit 执行测试。非图形界面浏览器。
其实就是换个浏览器,只是这个浏览器没有图形界面而已. browser = webdriver.Chrome() 换成 browser = webdriver.Remote(desired_capabi ...
- Rightmost Digit(最后一位数字)
Description Given a positive integer N, you should output the most right digit of N^N. Input The ...
- Java 集合框架之Collection
此图是 java 中 Collection 相关的接口与类的关系的类图.其中,类只是集合框架的一部分,比较常用的一部分. 第一次画类图,着实很费劲,不过收获也不小. 下面是相关接口和类的解释说明.文字 ...
- MVC4 DropDownList (二) — 省市联动
1.添加省份和城市类 //省份 public class Province { public int Id { get; set; } public string Name { get; set; } ...