题意就是一个给出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. 在ReactNative中使用Typescript

    在ReactNative中使用Typescript 少侠放心,跟着我的这个步骤走,保你完美在RN项目中使用Typescript,废话不多说,走你 1.全局安装create-react-native-a ...

  2. React中的全选反选问题

    全选反选问题 1.在state里维护一个数组,例如showArr:[] 2.绑定点击事件的时候将当前这个当选按钮的index加进来 <span className='arrow' onClick ...

  3. PHP创建MySQL并引入后执行sql语句

    一:创建sql.php文件 <?php function sqlMethod($sql){ $servername = "localhost"; $username = &q ...

  4. fabric Report API

    1.Token生成 接口 : post https://fabric.io/oauth/token 请求头:Headers Content-Type : application/json 正文: bo ...

  5. sqlite3 简单实用方法

    打开数据库:sqlite3.exe test.db 显示所有表: .tables 退出 sqlite3:.quit 还有个问题,已经打开一个数据库文件了. 不知道如何在不退出命令行的情况下,更换另一个 ...

  6. python查询mysql数据

    >>>cur.execute("select * from 表名") >>>lines=cur.fetchall() >>>f ...

  7. Element-ui学习使用

    这是我使用Element-ui的布局,排布的一个界面,原本我是使用WinfowsForm来做的一个摄像头注册以及查询的小工具,目前我关注前后端的开发,所以就想着能不能把这么个小工具,我用前后端的形式开 ...

  8. WebSocket 的使用

    Java 控制台程序实现类似广播功能 服务器端代码 添加 maven 依赖 <dependency> <groupId>javax.websocket</groupId& ...

  9. linux c fgetc()

    今天练习代码的时候碰见这样一个问题: 一个文件test.txt,文件内容为 1 2 4 5 在程序中读写这个文件,修改其内容,添加一行,将文件内容变成: 1 2 3 4 5 楼主的错误代码是这样的: ...

  10. 创龙DSP6748的DAC例程研究

    1. 创龙DSP6748开发板驱动TL5724这个DAC,输出指定的电压值,此程序是使用 IO 口模拟 SPI 实现与 TL5724 模块的数据交互. 2. 首先是初始化PSC函数 void PSCI ...