hdu 4749

题目很简单,不过题意很难看懂。

就是给一个标准的大小关系的队列,从原队列中找出最多的匹配子队列,感觉就像一个KMP算法+贪心;

不过这个题可能数据有点水把,竟然只要判断相邻的关系就可以A掉;

代码:

 1 #include<cstdio>
 2 #define maxn 100005
 3 using namespace std;
 4 int q[maxn],st[maxn],n,m,k;
 5 
 6 bool g(int a)
 7 {
 8     int i;
 9     for(i=a; i<a+m-1; i++)
10     {
11         if((q[i]==q[i+1]&&st[i-a]==st[i-a+1])||(q[i]<q[i+1]&&st[i-a]<st[i-a+1])||(q[i]>q[i+1]&&st[i-a]>st[i-a+1]))continue;
12         else break;
13     }
14     if(i==a+m-1)return 1;
15     return 0;
16 }
17 
18 int main()
19 {
20     while(scanf("%d%d%d",&n,&m,&k)!=EOF)
21     {
22         int ans=0;
23         for(int i=0; i<n; i++) scanf("%d",&q[i]);
24         for(int i=0; i<m; i++) scanf("%d",&st[i]);
25         for(int i=0; i<=n-m;) if(g(i))i=i+m,ans++;
26             else i++;
27         printf("%d
",ans);
28     }
29     return 0;
30 }
View Code
原文地址:https://www.cnblogs.com/yours1103/p/3335103.html