Kay match string Regal

Subject description:

Links: https://ac.nowcoder.com/acm/contest/1114/C
Source: Cattle-off network

N-m length of the text string, each string contains only '0' and '1'. Then there are times query Q, is given each time a string of length m, and containing only '0', '1' and '_'. As 10_1_1. Underline match '0' or '1'. I.e., four kinds 101111,101101,100111,100101 10_1_1 match string. Ask each number can obtain the current query string matching text strings with a n.

Enter a description:

The first input line n, m 
next n lines, each input line 01 a string of length m indicates a text string.
Input of the n + 2 Q row
Next Q lines, each input line of a string of m (comprising only '0', '1', '_').
1 <= n, m <= 1000,1 <= Q <= 3000.

Output Description:

For each query, the number of the output n of the current text string matching the query string have.
Example 1

Entry

5 6
101101
011011
100110
111000
101111
2
1011_1
1__1__

Export

2 
. 3 

compressed state
using the bitset

#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath> 
#pragma GCC optimize(2)

using namespace std;
typedef long long ll;
const int N = 1e3 + 5, mod = 1e9 + 9;
int n, m, qq;
bitset<N> Map[N], p, q;
char s[N];


int main()
{
//    cin.tie(0);
//    cout.tie(0);
//    ios::sync_with_stdio(0);
    cin >> n >> m;
    for (int i = 0; i < n; ++i){
        scanf("%s", s);
        for (int j = 0; j < m; ++j)
            if (s[j] == '1') Map[i][j] = 1;
            else Map[i][j] = 0;
    }
    cin >> qq;
    while (qq--){
        scanf("%s", s);
        for (int i = 0; i < m; ++i){
            if (s[i] == '_') {
                p[i] = 0, q[i] = 0;
            } else {
                p[i] = 1;
                q[i] = s[i] == '1' ? 1 : 0;
            }
        }
        
        int ans = 0;
        for (int i = 0; i < n; ++i){
            if ((p & Map[i]) == q) {
                ans ++;
            }
        }
        
        cout << ans << endl;
    }
}
View Code

 

 

Guess you like

Origin www.cnblogs.com/mwh123/p/11671044.html