题目链接

Problem Description
Using regular expression to define a numeric string is a very common thing. Generally, use the shape as follows:
(0|9|7) (5|6) (2) (4|5)
Above regular expression matches 4 digits:The first is one of 0,9 and 7. The second is one of 5 and 6. The third is 2. And the fourth is one of 4 and 5. The above regular expression can be successfully matched to 0525, but it cannot be matched to 9634.
Now,giving you a regular expression like the above formula,and a long string of numbers,please find out all the substrings of this long string that can be matched to the regular expression.
 
Input
It contains a set of test data.The first line is a positive integer N (1 ≤ N ≤ 1000),on behalf of the regular representation of the N bit string.In the next N lines,the first integer of the i-th line is ai(1≤ai≤10),representing that the i-th position of regular expression has ai numbers to be selected.Next there are ai numeric characters. In the last line,there is a numeric string.The length of the string is not more than 5 * 10^6.
 
Output
Output all substrings that can be matched by the regular expression. Each substring occupies one line
 
Sample Input
4
3 0 9 7
2 5 7
2 2 5
2 4 5
09755420524
 
Sample Output
9755
7554
0524
 
Source
 
题意:输入N ,表示有一个长为N的子串,接下来N行,每行输入ai 和ai个数,表示有ai个数,表示子串第i个字符为ai个数中的一个,也就是这个子串的正则式,然后输入一个主串,要求输出这个主串中包含的所有的子串。
 
思路:使用bitset<N> b[10] ,b[i][j]表示值为i的数可以出现在子串的那些位置,即下标,那么对主串进行遍历 i=0:len-1 。另外定义一个变量bitset<N> ans ,每次先将ans左移一位,然后将最低位置1,然后令k=当前输入的数,将ans=ans&b[k], 如果当前ans[N-1]==1,那么主串s[i-N+1]~s[i]就是合法子串,输出;
 
代码如下:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <bitset>
using namespace std;
typedef long long LL;
const int M=*1e6+;
bitset<>b[];
bitset<>ans;
char s[]; int main()
{
int N;
while(scanf("%d",&N)!=EOF)
{
for(int i=;i<;i++) b[i].reset();
for(int i=;i<N;i++)
{
int n;
scanf("%d",&n);
for(int j=;j<=n;j++)
{
int k;
scanf("%d",&k);
b[k].set(i);
}
}
getchar();
gets(s);
ans.reset();
int len=strlen(s);
for(int i=;i<len;i++)
{
ans=ans<<;
ans.set();
ans=ans&b[s[i]-''];
if(ans[N-]==){
char c=s[i+];
s[i+]='\0';
puts(s+i-N+);
s[i+]=c;
}
}
}
return ;
}

hdu 5972---Regular Number(字符串匹配)的更多相关文章

  1. HDU 5972 Regular Number

    Regular Number http://acm.hdu.edu.cn/showproblem.php?pid=5972 题意: 给定一个字符串,求多少子串满足,子串的第i位,只能是给定的数(小于等 ...

  2. HDU 5972 Regular Number(ShiftAnd+读入优化)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5972 [题目大意] 给出一个字符串,找出其中所有的符合特定模式的子串位置,符合特定模式是指,该子串 ...

  3. hdu 5972 Regular Number 字符串Shift-And算法 + bitset

    题目链接 题意 给定两个串\(S,T\),找出\(S\)中所有与\(T\)匹配的子串. 这里,\(T\)的每位上可以有若干(\(\leq 10\))种选择,匹配的含义是:对于\(S\)的子串的每一位, ...

  4. HDU 5972 Regular Number(字符串shift - and算法)

    题目链接  HDU5972 2016 ACM/ICPC 大连区域赛 B题 我们预处理出$b[i][j]$,$b[i][j] = 1$的意义是数字$i$可以放在第$j$位. 然后就开始这个匹配的过程. ...

  5. HDU 1711 Number Sequence (字符串匹配,KMP算法)

    HDU 1711 Number Sequence (字符串匹配,KMP算法) Description Given two sequences of numbers : a1, a2, ...... , ...

  6. HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)

    HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author George ...

  7. HDU 1711(KMP)字符串匹配

    链接  HDU 1711 Number Sequence KMP 算法 我以自己理解写的,写的不对,不明白的地方海王子出来,一起共同学习: 字符串匹配 就是KMP,一般思想,用一个for循环找开头   ...

  8. HDU 5716 带可选字符的多字符串匹配(ShiftAnd)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5716 [题目大意] 给出一个字符串,找出其中所有的符合特定模式的子串位置,符合特定模式是指,该子串 ...

  9. HDU 2087 剪花布条(字符串匹配,KMP)

    HDU 2087 剪花布条(字符串匹配,KMP) Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出 ...

随机推荐

  1. c++ 面试题(数据库)

    1,索引的原理: https://www.cnblogs.com/songwenjie/p/9414960.html https://blog.csdn.net/qq_32924343/article ...

  2. 【测试工具】Macaca 自动遍历器 NoSmoke

    Macaca 提供的基础能力上研发出了一套多端深度遍历爬虫工具. 希望可以最大化减少UI 测试脚本的编写涵盖以下功能点: 支持iOS, Android,PC-Web 三个平台的自动化测试 同时可以通过 ...

  3. POJ-3268.SilverCowParty.(最短路 + 图的转置)

    本题思路:对原图和原图的逆图分别用一次最短路,找出最大值即可. 一开始是我是对每个顶点spfa搜了一波,结果判题时间巨长,还好这个题的数据量不是很大,所以就用了另一种思路. 参考代码:spfa单结点爆 ...

  4. windbg获取打印

    经常有QT MFC程序调用动态库无法查看内部打印 解决办法: 文件头部定义: #define UseDebugView #ifdef UseDebugView char g_Debug[256]; # ...

  5. Python项目--Scrapy框架(一)

    环境 win8, python3.7, pycharm 正文 1.Scrapy框架的安装 在cmd命令行窗口执行: pip install Scrapy 即可完成Scrapy框架的安装 2. 创建Sc ...

  6. go语言 http学习

    net/http库学习 概念 处理器 处理器:拥有ServeHTTP方法的接口(任何类型) 签名:ServeHTTP(http.ResponseWriter, *http.Request) Respo ...

  7. 给 Chrome浏览器 添加 Javascript小书签,查看当前页面全部加载的javascript文件及代码片段

    小书签又名 Bookmarklet,由英文单词 Bookmark 和 Applet 组合而来.简单地说,小书签就是把一段带有特定功能的 JavaScript 代码保存至收藏夹,当你需要的时候点击它来实 ...

  8. Powershell 脚本判断制定路径下文件是否存在(来源于网络-转载)

    $filelist=gc "file.txt" #获取要检查的文件列表 $csvs= new-object collections.arraylist #创建一个arraylist ...

  9. Java并发集合(一)-CopyOnWriteArrayList分析与使用

    CopyOnWriteArrayList分析与使用 原文链接: http://ifeve.com/java-copy-on-write/ 一.Copy-On-Write Copy-On-Write简称 ...

  10. 万能的一句话 json

    String str1 = new JavaScriptSerializer().Serialize(meetapply1);//meetapply1==object T