牛客练习赛53-C富豪凯匹配串

BItsit的合理使用?

咱也不知道,咱也不敢问。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1000 + 5, M = 2e4 + 5;
int n, m, Q;
bitset<N> a[N], p, q;
char s[N];
int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++) {
        scanf("%s", s);
        for (int j = 0; j < m; j++)
            a[i][j] = s[j]=='1'? 1:0;
    }
    scanf("%d", &Q);
    while (Q--) {
        scanf("%s", s);
        int ans = 0;
        for (int i = 0; i < m; i++) {
            if (s[i] == '_') p[i]=q[i]=0;//方便之后进行子串的匹配 
            else p[i] = 1, q[i]=s[i]=='1'? 1:0;//手模一下? 
        }
        for(int i = 0; i < n; i++){
            if((p&a[i])==q){//bitsit可以进行& ^ | >> <<等运算 
               ans++;        //&运算 0无论与1还是0都是0,用来表示_可以是0也可以是1 
            }
        } 
        printf("%d
", ans);
    }
    return 0;
}
作者:wilxx
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
原文地址:https://www.cnblogs.com/wilxx/p/11658366.html