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.如有多种解输出任意一个. 思路:搞 ...
随机推荐
- Python函数中的参数
形参:形式参数 实参:实际参数 1.普通参数:严格按照顺序将实参赋值给形参. 2.默认参数:必须放置在参数列表的最后. 3.指定参数:将实参赋值给制定参数. 4.动态参数: *:默认将传入的参数,全部 ...
- ruby json解析&生成
JSON 通常用于与服务端交换数据. 在接收服务器数据时一般是字符串. 我们可以使用 JSON.parse() 方法将数据转换为 ruby 对象. 一. json字符串解析 require 'json ...
- Python3 os模块&sys模块&hashlib模块
''' os模块 非常重要的模块 ''' import os # print(os.getcwd()) # 获取当前工作目录 # os.chdir(r'路径名') # 改变当前工作目录 # print ...
- loj136 (最小瓶颈路,多次询问)
题目描述 给定一个包含 n nn 个节点和 m mm 条边的图,每条边有一个权值.你的任务是回答 k kk 个询问,每个询问包含两个正整数 s ss 和 t tt 表示起点和终点,要求寻找从 s ss ...
- error C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'
1.error C2471: cannot update program database vc90.pdb 解决方案:https://blog.csdn.net/shuixin536/article ...
- Linux初步——常用简单命令
散乱的记录,目前是边学边用,以后有机会再整理 curl命令 发起一个HTTP请求,如:curl "http://www.baidu.com" 加上-I选项查看HTTP协议头的信息, ...
- FJOI 2019 游记
(FJOI 2019 滚粗记) Day 0 早上刷了一些水题,然后就上路了. (画图3D好好玩) 来得晚只有十几分钟时间看考场,于是连试机题都没有Ak. Day 1 果然我还是太菜了 走过来的时候再讨 ...
- spring location设置本地路径
<context:property-placeholder location="file:D:/jdbc.properties"/> 直接在路径前加上 file:
- localStorage简析
声明:引用自http://www.cnblogs.com/st-leslie/p/5617130.html 一.什么是localStorage.sessionStorage 在HTML5中,新加入了一 ...
- Qt 使用irrlicht(鬼火)3D引擎
项目中需要加载简单的3D场景.资深老前辈推荐使用开源小巧的引擎irrlicht. 关于irrlicht,来之百度百科 Irrlicht引擎是一个用C++书写的高性能实时的3D引擎,可以应用于C++程序 ...