Codeforces Round #390 (Div. 2) E(bitset优化)
题意就是一个给出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优化)的更多相关文章
- Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)
http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...
- 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 ...
- Codeforces Round #390 (Div. 2) A. Lesha and array splitting
http://codeforces.com/contest/754/problem/A 题意: 给出一串序列,现在要把这串序列分成多个序列,使得每一个序列的sum都不为0. 思路: 先统计一下不为0的 ...
- Codeforces Round #390 (Div. 2)
时隔一个月重返coding…… 期末复习了一个月也不亏 倒是都过了…… 就是计组61有点亏 复变68也太低了 其他都还好…… 假期做的第一场cf 三道题 还可以…… 最后room第三 standing ...
- Codeforces Round #390 (Div. 2) A B C D
这是一场比较难的div2 ... 比赛的时候只出了AB A很有意思 给出n个数 要求随意的把相邻的数合并成任意多数 最后没有为0的数 输出合并区间个数与区间 可以想到0可以合到任何数上并不改变该数的性 ...
- Codeforces Round #390 (Div. 2) D
All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring s ...
- 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. ...
- 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 ...
- Codeforces Round #390 (Div. 2) A+B+D!
A. Lesha and array splitting 水题模拟.(0:10) 题意:给你一个n个元素的数组,求能否把这个数组分成若干连续小段,使得每段的和不为0.如有多种解输出任意一个. 思路:搞 ...
随机推荐
- 02 shell编程之条件语句
Shell编程之条件语句 学习目标: 掌握shell脚本条件测试 掌握if语句编程 目录结构: 条件测试 条件测试概述 l 对特定的条件进行判断,以决定如何执行操作 l 测试的方法 方法1:tes ...
- bootStrap的轮播
1.1如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...
- Python起源与发展
Python的创始人为吉多*范罗苏姆(Gudio van Rossum) 1.1989年的圣诞节期间,吉多*范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的解释程序,作为ABC语言的一种继承. 2. ...
- C#中给WebClient添加代理Proxy
效果图: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; ...
- js 节点
var chils= s.childNodes; //得到s的全部子节点 var par=s.parentNode; //得到s的父节点 var ns=s.nextSbiling; //获得s的下 ...
- zabbix监控nginx服务状态
nginx需要安装--with-http_stub_status_module模块 $ nginx -V nginx version: nginx/1.12.2 built by gcc 4.8.5 ...
- Python学习手册之函数和模块
在上一篇文章中,我们介绍了 Python 的控制结构,现在我们介绍 Python 函数和模块. 查看上一篇文章请点击:https://www.cnblogs.com/dustman/p/9976234 ...
- 一笔画问题 南阳acm42(貌似没用到什么算法)
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...
- List集合中的对象比较,取出不同对象
今天在做金碟系统与我们系统的对接的时候需要做一个客户同步 在同步时,需要比较对象,对查询出的数据库的数据进行比较 for(int i=0;i<list2.size();i++){ if(! li ...
- rhel6.4扩充swap分区
状况:Red hat 6.4 swap分区不足 解决:扩充swap ================================================================== ...