题目链接

题目都看不懂,做毛线。。。看懂了之后就是kmp出,所有的匹配区间,然后DP可以写,贪心也可以做把,DP应该需要优化一下,直接贪,也应该对的,经典贪心问题。

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int s1[],s2[];
int p[],o[];
int next[];
int flag[];
int judge(int x,int y)
{
if(x == y)
return ;
else if(x > y)
return ;
else
return -;
}
int main()
{
int n,m,k,len1,len2,i,j;
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
memset(flag,,sizeof(flag));
for(i = ;i < n;i ++)
scanf("%d",&p[i]);
for(i = ;i < m;i ++)
scanf("%d",&o[i]);
if(m == )
{
printf("%d\n",n);
continue;
}
for(i = ;i < m-;i ++)
s1[i] = judge(o[i+],o[i]);
for(i = ;i < n-;i ++)
s2[i] = judge(p[i+],p[i]);
len1 = m-;//kmp
len2 = n-;
next[] = -;
j = -;
for(i = ;i < len1;i ++)
{
while(j >= &&s1[j+] != s1[i])
j = next[j];
if(s1[j+] == s1[i]) j ++;
next[i] = j;
}
j = -;
for(i = ;i < len2;i ++)
{
while(j >= &&s1[j+] != s2[i])
j = next[j];
if(s1[j+] == s2[i])j ++;
if(j == len1-)
{
flag[i-len1+] = ;
j = next[j];
}
}
int ans = ;
for(i = ;i < n-;i ++)
{
if(flag[i])
{
ans ++;
i = i + m - ;
}
}
printf("%d\n",ans);
}
return ;
}

HDU 4749 Parade Show(贪心+kmp)的更多相关文章

  1. HDU 4749 Parade Show(暴力水果)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4749 Problem Description   2013 is the 60 anniversary ...

  2. HDU 4749 Parade Show 2013 ACM/ICPC Asia Regional Nanjing Online

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4749 题目大意:给一个原序列N,再给出一个序列M,问从N中一共可以找出多少个长度为m的序列,序列中的数 ...

  3. HDU 4749: Parade Show

    看大神代码,发现上交大神很棒的一个思路 题意: 在源数字串中找出尽量多的连续子串,要求子串任意两值的大小关系与目标串相同位置的值的大小关系相同.求源串能拿出的子串的最大数量. 关键词: RK-Hash ...

  4. HDU 4442 Physical Examination(贪心)

    HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...

  5. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  6. HDU4749 Parade Show(KMP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4749 题意:给出两个数字串A.B.问A中有多少不相交的子串a能匹配B.匹配的意思是a中任意两个位置i和 ...

  7. hdu 2594 Simpsons’ Hidden Talents KMP

    Simpsons’ Hidden Talents Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java ...

  8. HDU 3374 String Problem(KMP+最大/最小表示)

    String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  9. [HDU 3689]Infinite monkey theorem (KMP+概率DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3689 黄老师说得对,题目只有做wa了才会有收获,才会有提高. 题意:一个猴子敲键盘,键盘上有n个键,猴 ...

随机推荐

  1. Big Data, MapReduce, Hadoop, and Spark with Python

    此书不错,很短,且想打通PYTHON和大数据架构的关系. 先看一次,计划把这个文档作个翻译. 先来一个模拟MAPREDUCE的东东... mapper.py class Mapper: def map ...

  2. 【openGL】四面体

  3. 不定义JQuery插件,不要说会JQuery 分类: JavaScript 2014-11-24 14:18 155人阅读 评论(0) 收藏

    一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写$("#"),$("."),写了几年就对别人说非常熟悉JQuery.我曾经也是这样的人 ...

  4. PGA

    Server Process PGA   1.PGA作用   2.PGA構成      1)private sql area      2)session memory          3)sql ...

  5. 数据结构之图 Part2 - 1

    邻接矩阵 网上很少有C# 写图的数据结构的例子,实际的项目中也从来没用过Array 这坨东西,随手写个,勿喷. namespace LH.GraphConsole { public struct Gr ...

  6. Win10 for Phone 裁剪控件

    <Page.BottomAppBar> <CommandBar x:Name="appBar"> <AppBarButton Label=" ...

  7. SQLServer 维护脚本分享(09)相关文件读取

    /********************[读取跟踪文件(trc)]********************/ --查看事件类型描述 SELECT tc.name,te.trace_event_id, ...

  8. Blog Starting...

    30出头,开始Blog记录学习生活的点滴,待40时再回来一看.

  9. python 继承

    继承一个类 如果已经定义了Person类,需要定义新的Student和Teacher类时,可以直接从Person类继承: class Person(object): def __init__(self ...

  10. AOP静态代理解析1-标签解析

    AOP静态代理使用示例见Spring的LoadTimeWeaver(代码织入) Instrumentation使用示例见java.lang.instrument使用 AOP的静态代理主要是在虚拟机启动 ...