题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4749

10 5 10 2 4 2 4 2 4 2 4 2 4 1 2 1 2 1
1
题意:
给出了一列数,再给出了一列参照的数列其每个数代表一个高度且须满足大小关系,求可以将所给的数列分割成多少个满足参照数列个数和高度的数列!
PS:
数据太水了,暴力过了! 正解貌似是KMP, 算了日后再补正解吧!
代码如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn = 100017;
int a[maxn], b[maxn];
int main()
{
int n, m, k;
while(~scanf("%d%d%d",&n,&m,&k))
{
for(int i = 0; i < n; i++)
{
scanf("%d",&a[i]);
}
for(int i = 0; i < m; i++)
{
scanf("%d",&b[i]);
}
int cont = 0;
for(int i = 0; i <= n-m; i++)
{
int tt = 0;
for(int j = 0,l = i; l < m+i-1; l++,j++)
{
if((a[l]==a[l+1]&&b[j]==b[j+1]) || (a[l]>a[l+1]&&b[j]>b[j+1]) || (a[l]<a[l+1]&&b[j]<b[j+1]))
{
tt++;
}
else
break;
}
if(tt == m-1)
{
cont++;
i+=m-1;
}
}
printf("%d\n",cont);
}
return 0;
}
原文地址:http://blog.csdn.net/u012860063/article/details/40352511