zoukankan      html  css  js  c++  java
  • hdu 5972 Regular Number(Shift-And算法)

    题目链接:hdu 5972 Regular Number

    题意:

    给你一个字符串,现在让你输出该字符串所有的合法子串。

    合法子串定义为:对应位置的字符合法。

    对应位置的合法字符会给你。

    题解:

    据说这是一个名字叫做Shift-And算法。其实就是一个bitset优化的字符串匹配。

    这里我将它写成板子。

     1 #include<bits/stdc++.h>
     2 #define F(i,a,b) for(int i=a;i<=b;++i)
     3 using namespace std;
     4 
     5 namespace Shift_And{
     6     const int N=5e6+7,tyn=11;
     7     bitset<1007>s[tyn],ans;
     8     int len;char str[N];
     9     void in(int n)
    10     {
    11         F(i,0,tyn-1)s[i].reset();
    12         ans.reset();
    13         F(i,1,n)
    14         {
    15             int num,x;
    16             scanf("%d",&num);
    17             F(j,1,num)scanf("%d",&x),s[x][i]=1;
    18         }
    19         getchar(),gets(str+1),len=strlen(str+1);
    20     }
    21     void shift_and(int n)
    22     {
    23         F(i,1,len)
    24         {
    25             ans=ans<<1,ans[1]=1;
    26             ans&=s[str[i]-'0'];
    27             if(ans[n])
    28             {
    29                 char tp=str[i+1];
    30                 str[i+1]=0;
    31                 puts(str+i-n+1);
    32                 str[i+1]=tp;
    33             }
    34         }
    35         
    36     }
    37 }
    38 
    39 int main()
    40 {
    41     int n;
    42     while(~scanf("%d",&n))
    43     {
    44         Shift_And::in(n);
    45         Shift_And::shift_and(n);
    46     }
    47     return 0;
    48 }
    View Code
  • 相关阅读:
    adapter 异步加载
    退出应用
    scrollview 和 edittext 焦点冲突
    判断字符串
    generate portable version cannot addon plugin(buffer var)
    在ubuntu上面安装perl
    TV
    关于xilinx ise10.1与modelsim仿真库编译
    迅雷tips
    Verilog log2 函数
  • 原文地址:https://www.cnblogs.com/bin-gege/p/7647629.html
Copyright © 2011-2022 走看看