HDU-5972 Regular Number(Shift-And)
来源:互联网 发布:淘宝店铺邮费怎么设置 编辑:程序博客网 时间:2024/06/18 05:36
Regular Number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 880 Accepted Submission(s): 212
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.
(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 isai(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
题解:Shift-And算法模板题
#include<bits/stdc++.h>using namespace std;const int MXP = 1e3 + 5;const int MXT = 5e6 + 5;char P[MXP],T[MXT];bitset<MXP>B[256],D; //B数组大小为字符的种数,长度为MXPvoid pre_solve(char P[]){ int len=strlen(P); D.reset(); for(int i=0;i<256;i++) B[i].reset(); for(int i=0;i<len;i++) B[P[i]].set(i);}int n;int shift_and(char T[]) { int m=strlen(T); //pre_solve(P); for (int i = 0; i < m; i++) { D=(D<<1).set(0)&B[T[i]]; if (D[n-1]) { char ch=T[i+1]; T[i+1]=0; puts(T+i-n+1); T[i+1]=ch; } } return -1;}char tmp[MXT];int main(){ //freopen("in.txt","r",stdin); scanf("%d",&n); int num, x; for (int i = 0; i < n; i++) { scanf("%d",&num); for (int j = 1; j <= num; j++) { scanf("%d",&x); B[x+'0'].set(i); } } getchar(); gets(tmp); shift_and(tmp); return 0;}
阅读全文
0 0
- HDU-5972 Regular Number(Shift-And)
- HDU 5972 Regular Number(Shift-And)
- HDU 5972 Regular Number Bitset (字符串匹配shift and/or)
- shift-and(HDU 5972 && 2016ICPC大连 B: Regular Number)
- HDU 5972 Regular Number Bitset优化字符串匹配 +Shift-And算法
- HDU 5972 Regular Number (bitset)
- HDU 3443 Shift Number
- hdu 3443 Shift Number (水)
- HDU 5972 Regular Number Bitset优化字符串匹配
- hdu 5972 Regular Number bitset优化字符串匹配
- hdu 3443(水题,公式)Shift Number
- Shift Number
- regular~ number~
- hdu 5972 Regular Number (bitset优化匹配) 2016大连现场赛
- Regular polygon(HDU 6055)
- Logical shift and Arithmetic shift
- shift-And / shift-Or 算法
- TOJ 3534.Shift Number
- 第3部分 装载与动态链接---(6)可执行文件的装载与进程
- 用matlab怎么画图,比如y =exp(x^2)?
- 欢迎使用CSDN-markdown编辑器
- Linux系统编程——进程同步与互斥:System V 信号量
- spring的dao接口扫描(MapperFactoryBean与MapperScannerConfigurer)
- HDU-5972 Regular Number(Shift-And)
- mapper绑定异常 springframework.web.util.NestedServletException
- JSP技术的总结
- 单链表含环的各种面试题
- 关于闭包在IE9及之前浏览器的内存泄漏问题
- python爬虫
- 283. Move Zeroes
- ubuntu shell推荐——zsh
- mysql里面的伪事务-----MyISAM存储引擎的锁机制