HDU 5972 Regular Number (bitset)
来源:互联网 发布:爱思软件助手 编辑:程序博客网 时间:2024/06/16 17:05
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
43 0 9 72 5 72 2 52 4 509755420524
Sample Output
975575540524
题意
有
思路
一开始想到把所有组的数压进一个
一个更优雅的做法是:我们用一个
AC 代码
#include<bits/stdc++.h>#define IO ios::sync_with_stdio(false);\ cin.tie(0);\ cout.tie(0);using namespace std;const int maxn = 1e3+10;const int maxm = 5e6+10;bitset<maxn>a[10],ans;char str[maxm];void init(){ for(int i=0; i<10; i++) a[i].reset(); ans.reset();}int main(){ int n; while(~scanf("%d",&n)) { init(); for(int i=0; i<n; i++) { int ai; scanf("%d",&ai); for(int j=0; j<ai; j++) { int x; scanf("%d%*c",&x); a[x].set(i); } } gets(str); int len = strlen(str); for(int i=0; i<len; i++) { ans<<=1; ans[0]=1; ans&=a[str[i]-'0']; if(ans[n-1]==1) { char tmp = str[i+1]; str[i+1] = 0; puts(str+i-n+1); str[i+1] = tmp; } } } return 0;}
- HDU 5972 Regular Number (bitset)
- HDU 5972 Regular Number Bitset优化字符串匹配
- hdu 5972 Regular Number bitset优化字符串匹配
- HDU 5972 Regular Number Bitset (字符串匹配shift and/or)
- hdu 5972 Regular Number (bitset优化匹配) 2016大连现场赛
- HDU 5972 Regular Number Bitset优化字符串匹配 +Shift-And算法
- HDU-5972 Regular Number(Shift-And)
- HDU 5972 Regular Number(Shift-And)
- HDU5972 Regular Number (ShiftAnd算法+bitset)
- hdu5972 Regular Number (bitset应用+快速匹配+shiftAnd匹配算法学习模板)
- shift-and(HDU 5972 && 2016ICPC大连 B: Regular Number)
- HDU 3711 Binary Number【水题】【bitset】
- HDU-5961(bitset)
- hdu 6085(bitset)
- regular~ number~
- hdu 2051 Bitset (java)
- hdu-Bitset
- Regular polygon(HDU 6055)
- 网传《王者荣耀》团队年终奖100个月工资?腾讯:传言太离谱
- 我工作的这两年
- 长连接/websocket/SSE等主流服务器推送技术比较
- 8.gcc编译器
- 部署你的第一个Spring Boot 应用
- HDU 5972 Regular Number (bitset)
- java 实现简单的自动装配
- 数据结构——链式队列模板类实现
- 赋值=解压序列--cookbook读书笔记
- C语言——字符统计
- Nginx概览
- DOM4J jar包 获取xml文件中的标签内容
- Apply and arrays: three tricks
- 【codevs 1039】数的划分&&【Openjudge 666】放苹果