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.如有多种解输出任意一个. 思路:搞 ...
随机推荐
- nginx 只允许域名访问,禁止IP访问
在nginx中为了防止,通过ip地址或者没有备案的域名代理到nginx上,可以在nginx中配置来阻止这一操作 #只可以用域名访问(此处的server是新增,并不是在原有的server基础上修改),默 ...
- JS高级. 04 增删改查面向对象版歌曲管理、递归、
增 数组.push() 删 数组.splice(开始删除索引,删除几个) 在当前对象中调用当前对象的方法中和属性,必须用this调用 nodeType判断节点类型 节点.nodeType == 1: ...
- docker化安装grafana
继续进行docker改造. 1. 找镜像.拉取镜像 [root@devlop ~]# docker search grafana INDEX NAME DESCRIPTION STARS OFFICI ...
- springboot学习(2)
WebMvcConfigurerAdapter 在springboot2.0及以上版本过时问题 WebMvcConfigurerAdapter已经过时,替代方案: 1 实现 WebMvcConfigu ...
- 使用SQLite删除Mac OS X 中launchpad里的快捷方式
一般情况下,从App Store安装的应用程序,如果应用删除,那么launchpad里对应的图标会一起删除了. 而对于不是通过App Store安装的应用程序,删除应用程序,Launchpad中很可能 ...
- 利用nodejs实现商品管理系统(二)
下面实现商品管理系统 第一步:对应的ejs与数据交换的编写格式. 商品列表界面product.ejs <% for(var i=0;i<list.length;i++){%> < ...
- (数据科学学习手札09)系统聚类算法Python与R的比较
上一篇笔者以自己编写代码的方式实现了重心法下的系统聚类(又称层次聚类)算法,通过与Scipy和R中各自自带的系统聚类方法进行比较,显然这些权威的快捷方法更为高效,那么本篇就系统地介绍一下Python与 ...
- 【Leetcode】647. Palindromic Substrings
Description Given a string, your task is to count how many palindromic substrings in this string. Th ...
- CC3200在sl_Start函数处不断重启复位的原因解析
1. 使用过程中,自己写的工程,发现CC3200一直重启,首先需要定位出现重启的函数?看门狗复位,还是程序跑飞复位?NWP的版本不匹配?经过测试找到出问题的函数,这个函数是启动网络的函数. lRetV ...
- What to do when Enterprise Manager is not able to connect to the database instance (ORA-28001)
摘自:http://dbtricks.com/?p=34 If you are trying to connect to the Oracle enterprise Manger and you ge ...