Regular Number HDU

Regular Number

 HDU - 5972 

题意:

用到了bitset和Shift-And匹配算法

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 5e6+10;
 4 bitset<1010> B[11], ans;
 5 char s[maxn];
 6 int main(){
 7     int n;
 8     //freopen("in.txt", "r", stdin);
 9    // for(int i = 0 ; i < 11; i++) B[i].reset();
10    // ans.reset();
11     scanf("%d", &n);
12     for(int i = 0; i < n; i++){
13         int m, x;
14         scanf("%d", &m);
15         for(int j = 0; j < m; j++) {
16             scanf("%d", &x);
17             B[x].set(i);
18         }
19     }
20     scanf("%s", s);
21     int len = strlen(s);
22     for(int i = 0; i < len; i++){
23         ans <<= 1;
24         ans[0] = 1;
25         ans &= B[s[i] - '0'];
26         if(ans[n-1] == 1) {
27             char c = s[i+1];
28             s[i+1] = 0;
29             puts(&s[i-n+1]);
30             s[i+1] = c;
31         }
32     }
33     return 0;
34 }
View Code
原文地址:https://www.cnblogs.com/yijiull/p/7705290.html