题目链接

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. vue 和 react 路由跳转和传参

                      react  1 .跳转方式加传参 this.props.history.push({ //地址 pathname: '/film/Details', //路由传参 ...

  2. [leetcode]48. Rotate Image旋转图像

    You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...

  3. entity framework core 生成 postgresql 数据库实体

    .net core 2.0 使用db first 方式生成 表 和context PM 控制台运行命令出错 Scaffold-DbContext "Host=localhost;Databa ...

  4. 杨其菊201771010134《面向对象程序设计Java》第二周学习总结

    第三章 Java基本程序设计结构 第一部分:(理论知识部分) 本章主要学习:基本内容:数据类型:变量:运算符:类型转换,字符串,输入输出,控制流程,大数值以及数组. 1.基本概念: 1)标识符:由字母 ...

  5. bittorrent 学习(一) 种子文件分析与bitmap位图

    终于抽出时间来进行 BITTORRENT的学习了 BT想必大家都很熟悉了,是一种文件分发协议.每个下载者在下载的同时也在向其他下载者分享文件. 相对于FTP HTTP协议,BT并不是从某一个或者几个指 ...

  6. flask更改已有的response

    今天遇到个问题,需要更改返回的response,但框架已经生成了一个response,所以需要直接更改. 试着找了找解决办法,最终解决方式如下: #下文中payload的类型是 # class Res ...

  7. 《Miracle_House团队》第一次作业:团队亮相

    Our Team:Miracle_House part 1 团队成员组成: NO.1  汝春瑞   201571030125   (组长) Style:乐观开朗,认真踏实,责任心强,还有就是爱笑.随和 ...

  8. innobackupex 备份 Xtrabackup 增量备份

    Mysql增量备份Xtrabackup中包含两个工具:•        xtrabackup - 用于热备份innodb, xtradb表的工具,不能备份其他表(MYISAM表).•        i ...

  9. 2019.02.17 spoj Query on a tree VII(链分治)

    传送门 跟QTREE6QTREE6QTREE6神似,改成了求连通块里的最大值. 于是我们对每条链开一个heapheapheap维护一下即可. MDMDMD终于1A1A1A链分治了. 代码: #incl ...

  10. MySQL-5.7安装

    2.1 下载mysql 网址:https://www.mysql.com/ [root@localhost ~]# mkdir -p /root/soft/MySQL [root@localhost ...