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——题解的更多相关文章

  1. POJ3690 Constellations 【KMP】

    Constellations Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5044   Accepted: 983 Des ...

  2. POJ3690:Constellations(二维哈希)

    Constellations Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6822   Accepted: 1382 题目 ...

  3. POJ3690 Constellations

    嘟嘟嘟 哈希 刚开始我一直在想二维哈希,但发现如果还是按行列枚举的话会破坏子矩阵的性质.也就是说,这个哈希只能维护一维的子区间的哈希值. 所以我就开了个二维数组\(has_{i, j}\)表示原矩阵\ ...

  4. 【poj3690】Constellations 哈希

    传送门 题目分析 考虑将大矩阵的每个1*q矩阵哈希值求出,然后让小矩阵的第一行在大矩阵中找,如果找到,并且能匹配所有行则出现过.否则没出现过. 在初始化1*q矩阵时可以进行优化:假设该行为123456 ...

  5. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  6. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  7. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  8. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  9. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

随机推荐

  1. nginx 路由配置

    nginx中location对url匹配: 语法:location [=|~|~*|^~] /uri/ { … } 当匹配中符合条件的location,则执行内部指令:如果使用正则表达式,必须使用~* ...

  2. uvaoj 1081510815 - Andy's First Dictionary(set应用)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=835&page= ...

  3. 【wx:if】小程序条件渲染的使用说明

    语法,以view为例: <view xw:if="{{条件}}">aaaa</view> <view xw:elif="{{条件}}&quo ...

  4. 【RandomString】- 随机字符串

    RandomString  随机字符串的用法

  5. POJ 3046

    题目大意:蚂蚁牙黑,蚂蚁牙红:有A只蚂蚁,来自T个家族,分别记为ant[i]个.同一个家族的蚂蚁长得一样,但是不同家族的蚂蚁牙齿颜色不同.任取n只蚂蚁(S <= n <= B),求能组成几 ...

  6. 简单的图片滑动效果插件 jQuery.iocnSlider.js

    近几日在制作一个客户引导页面,其中有一个图片展示而且带滑动的效果.好久没练手了,索性自己写一个插件吧. 依据设计原型,需要满足两套分辨率下图片不同的尺寸,所以在css中使用了media query的相 ...

  7. browsersync 插件

    自从发现了这个 browsersync 插件 ... 在也不用每次改一行代码就去手动刷新 HTML 页面了省去了很多繁琐的操作,当有多个显示器的时候,更加的方便,在IDEA上编辑代码之后,点击 com ...

  8. LeetCode - 389. Find the Difference - 三种不同解法 - ( C++ ) - 解题报告

    1.题目大意 Given two strings s and t which consist of only lowercase letters. String t is generated by r ...

  9. UVa 340 - Master-Mind Hints 解题报告 - C语言

    1.题目大意 比较给定序列和用户猜想的序列,统计有多少数字位置正确(x),有多少数字在两个序列中都出现过(y)但位置不对. 2.思路 这题自己思考的思路跟书上给的思路差不多.第一个小问题——位置正确的 ...

  10. URAL 1519 Formula 1(插头DP,入门题)

    Description Background Regardless of the fact, that Vologda could not get rights to hold the Winter ...