HDUOJ -----1686
Oulipo
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3770 Accepted Submission(s): 1485
Tout avait Pair normal, mais tout s’affirmait faux. Tout avait Fair normal, d’abord, puis surgissait l’inhumain, l’affolant. Il aurait voulu savoir où s’articulait l’association qui l’unissait au roman : stir son tapis, assaillant à tout instant son imagination, l’intuition d’un tabou, la vision d’un mal obscur, d’un quoi vacant, d’un non-dit : la vision, l’avision d’un oubli commandant tout, où s’abolissait la raison : tout avait l’air normal mais…
Perec would probably have scored high (or rather, low) in the following contest. People are asked to write a perhaps even meaningful text on some subject with as few occurrences of a given “word” as possible. Our task is to provide the jury with a program that counts these occurrences, in order to obtain a ranking of the competitors. These competitors often write very long texts with nonsense meaning; a sequence of 500,000 consecutive 'T's is not unusual. And they never use spaces.
So we want to quickly find out how often a word, i.e., a given string, occurs in a text. More formally: given the alphabet {'A', 'B', 'C', …, 'Z'} and two finite strings over that alphabet, a word W and a text T, count the number of occurrences of W in T. All the consecutive characters of W must exactly match consecutive characters of T. Occurrences may overlap.
One line with the word W, a string over {'A', 'B', 'C', …, 'Z'}, with 1 ≤ |W| ≤ 10,000 (here |W| denotes the length of the string W).
One line with the text T, a string over {'A', 'B', 'C', …, 'Z'}, with |W| ≤ |T| ≤ 1,000,000.
kmp ....经典题
思路清晰,就不多说啦!...
就是求目标串在主串中出现几次,即匹配几次,,.
代码:
/*@coder 龚细军*/
#include<iostream>
#include<string>
#include<vector>
using namespace std; int main()
{
int t,i,j;
string pw,ps;
cin>>t;
while(t--)
{
i=,j=-;
cin>>pw>>ps; /*pw作为目标串,ps作为主串*/
int lenpw=pw.length();
int lenps=ps.length();
vector<int>next(lenpw+,);
next[i]=-;
while(i<lenpw)
{
if(j==-||pw[i]==pw[j])
{
++i;
++j;
if(pw[i]!=pw[j])
next[i]=j;
else
next[i]=next[j];
}
else
j=next[j];
}
i=-,j=-;
int ans=;
while(i<lenps)
{
if(j==-||pw[j]==ps[i])
{
++i;
++j;
}
else
j=next[j];
if(j==lenpw)
ans++;
}
printf("%d\n",ans);
}
return ;
}
HDUOJ -----1686的更多相关文章
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- FZU 1686 神龙的难题 (重复覆盖)
Problem 1686 神龙的难题 Accept: 397 Submit: 1258Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...
- hdu 1686 KMP模板
// hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup
hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...
- hdu 1686 Oulipo KMP匹配次数统计
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 分析:典型的KMP算法,统计字符串匹配的次数. 用Next数组压缩时间复杂度,要做一些修改. / ...
- FZU 1686 神龙的难题 (DLX)
神龙的难题 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- PQJ 1686(栈栈栈)
PQJ 1686(栈栈栈) 用栈解决问题 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I6 ...
- FZU 1686 神龙的难题(DLX反复覆盖)
FZU 1686 神龙的难题 pid=1686" target="_blank" style="">题目链接 题意:中文题 思路:每个1看成列, ...
随机推荐
- flask_wtf/wtforms几个坑点,先简单记此
1.@pluginquery.route('/app_include_plugins', methods=['GET','POST']) methods必须填写 2.plu_incl_app = St ...
- wtforms的简单示例
1.先定义一个类: #!/usr/bin/env python # -*- coding: utf-8 -*- # Created by xxx on 2017/3/13 from wtforms i ...
- poj 1201 Intervals 解题报告
Intervals Time Limit: 2000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu Submit Statu ...
- nth-digit
https://leetcode.com/problems/nth-digit/ public class Solution { public int findNthDigit(int n) { in ...
- Leaflet绘制热力图【转】
http://blog.csdn.net/giser_whu/article/details/51485871 时下用的最多的开源二维webgis引擎应该是openlayers与leaflet了,le ...
- Unity的延迟管线
unity buildin deferred pipeline rt0 albedo rt1 spec rt2 normal rt3 emissive rt4 shadowmask rt3的使用方式 ...
- [leetcode]Convert Sorted List to Binary Search Tree @ Python
原题地址:http://oj.leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ 题意:将一条排序好的链表转换为二叉查找树 ...
- TypeError: 'newline' is an invalid keyword argument for this function 错误解决
出错代码: outputFile = open('output1.csv', 'w', newline='') # error line outputWriter = csv.writer(outpu ...
- MFC COM调用时出现E_OUTOFMEMORY错误
按照<com原理与应用>第五章写的基于MFC dll的COM,COM对象不是基于Automation的,自己映射了接口,也把潘爱民的源代码看了,感觉和他的代码一样呀,为什么在客户端用CoC ...
- 为什么好多人说win8不好用?
2012年8月就開始接触win8了,那时win8已经出来半年了:自从用了win8之后就感觉他比xp.win7桌面更绚丽.我就喜欢绚丽的桌面.至今使用win8已经两年了,可发现身边好多人都说win8不好 ...