题意就是一个给出2个字符矩阵,然后进行匹配,输出每个位置的匹配的结果

(超出的部分循环处理)

一种做法是使用fft,比较难写,所以没有写

这里使用一个暴力的做法,考虑到一共只出现26个字符

所以使用一个数组G[c][i][j]表示字符c是否出现在位置(i, j),即G[c]是一个01矩阵

可以使用bitset定义G

然后考虑匹配的时候

考虑要匹配的那个矩阵B,如果当前字符是?就跳过

如果不是,就考虑这个字符会对哪些匹配位置造成影响

用bitset表示一行的状态,然后使用and和左移、右移就可以更新答案矩阵

复杂度是O(n*m*r*c/32) (bitset优化)

#include <iostream>
#include <cstdio>
#include <bitset>
using namespace std;
const int N = ;
char str[];
bitset<N> G[][N], A[N];
int n, m, r, c;
bitset<N> shift(char c, int i, int x)
{
bitset<N> temp = G[c][i];
return (temp>>x)|(temp<<(m-x));
} int main()
{
//freopen("a.txt", "r", stdin);
scanf("%d %d", &n, &m);
for(int i = ; i < n; i ++)
{
scanf("%s", str);
for(int j = ; j < m; j++)
G[str[j]-'a'][i][j] = , A[i][j] = ;
}
scanf("%d %d", &r, &c);
for(int i = ; i < r; i++)
{
scanf("%s", str);
for(int j = ; j < c; j++)
{
char ch = str[j];
if(ch == '?') continue;
for(int k = ; k < n; k++)
A[k] = (A[k] & shift(ch-'a', (k+i)%n, j%m));
}
}
for(int i = ; i < n; i++)
{
for(int j = ; j < m; j++)
printf("%d", A[i][j] ? : );
printf("\n");
} }

Codeforces Round #390 (Div. 2) E(bitset优化)的更多相关文章

  1. Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)

    http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...

  2. Codeforces Round #390 (Div. 2) C. Vladik and chat(dp)

    http://codeforces.com/contest/754/problem/C C. Vladik and chat time limit per test 2 seconds memory ...

  3. Codeforces Round #390 (Div. 2) A. Lesha and array splitting

    http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的 ...

  4. Codeforces Round #390 (Div. 2)

    时隔一个月重返coding…… 期末复习了一个月也不亏 倒是都过了…… 就是计组61有点亏 复变68也太低了 其他都还好…… 假期做的第一场cf 三道题 还可以…… 最后room第三 standing ...

  5. Codeforces Round #390 (Div. 2) A B C D

    这是一场比较难的div2 ... 比赛的时候只出了AB A很有意思 给出n个数 要求随意的把相邻的数合并成任意多数 最后没有为0的数 输出合并区间个数与区间 可以想到0可以合到任何数上并不改变该数的性 ...

  6. Codeforces Round #390 (Div. 2) D

    All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring s ...

  7. Codeforces Round #390 (Div. 2) B

    Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. ...

  8. Codeforces Round #390 (Div. 2) A

    One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into sev ...

  9. Codeforces Round #390 (Div. 2) A+B+D!

    A. Lesha and array splitting 水题模拟.(0:10) 题意:给你一个n个元素的数组,求能否把这个数组分成若干连续小段,使得每段的和不为0.如有多种解输出任意一个. 思路:搞 ...

随机推荐

  1. React学习(3)——Router路由的使用和页面跳转

    React-Router的中文文档可以参照如下链接: http://react-guide.github.io/react-router-cn/docs/Introduction.html 文档中介绍 ...

  2. 深度解析JQuery Dom元素操作技巧

    深度解析JQuery Dom元素操作技巧 DOM是一种与浏览器.平台.语言无关的接口,使用该接口可以轻松访问页面中所有的标准组件,这篇文章给大家介绍了JQuery dom元素操作方法,写的十分的全面细 ...

  3. 课时102.CSS精灵图(掌握)

    我们这节课来介绍一个和背景图片相关的东西,精灵图 1.设么是css精灵图? css精灵图是一种图像合成技术 2.css精灵图作用 可以减少请求的次数,以及可以降低服务器处理压力 3.如何使用css精灵 ...

  4. php+sqlserver处理读取decimal 类型数据,不满1的数字会去掉0的问题

    php+sqlserver处理读取decimal 类型数据,如果数据不满1,会去掉0的问题.比如读取的数据是 0.05,会显示 .05 function convert_number($number) ...

  5. C# 生成机器码

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. vue2018年5月报错No parser and no file path given

    mac电脑直接: rm -rf node_modules rm package-lock.json npm install npm install prettier@~1.12.1 执行完这四个命令, ...

  7. Ubuntu中搭建Hadoop集群(简记)

    stp1:在Vmware虚拟机上创建Ubantu.2环境 步骤:文件—>新建虚拟机—>典型(下一步)—>下一步——>位置(不建议放c盘,文件地址一定要全英文)—>下一步— ...

  8. linux安装oracle远程客户端

    文章参考:http://blog.csdn.net/caomiao2006/article/details/11901123 感谢博友分享O(∩_∩)O~ 安装oracle 远程客户端(一般情况下本地 ...

  9. 记一次艰难的CTP调试

    一个atmel,mxt540e的CTP触摸屏. 中断配置为下降沿,输入上拉. 总是只能触发一次中断,中断脚就一直低电平,无法拉高.这只是表面现象   不停找底层I2C驱动,改代码,没用.要靠波形来说话 ...

  10. OpenCV入门:(七:OpenCV取随机数以及显示文字)

    1.随机颜色 OpenCV中自带了取随机数的方法,使用步骤: RNG rng( 0xFFFFFFFF ); 随机数 = rng.uniform( 下限,上限 ); 2.显示文字 , , bool bo ...