Hdu-4749 Parade Show
来源:互联网 发布:医院用软件 编辑:程序博客网 时间:2024/04/29 22:10
Description
2013 is the 60 anniversary of Nanjing University of Science and Technology, and today happens to be the anniversary date. On this happy festival, school authority hopes that the new students to be trained for the parade show. You should plan a better solution to arrange the students by choosing some queues from them preparing the parade show. (one student only in one queue or not be chosen)
Every student has its own number, from 1 to n. (1<=n<=10^5), and they are standing from 1 to n in the increasing order the same with their number order. According to requirement of school authority, every queue is consisted of exactly m students. Because students who stand adjacent in training are assigned consecutive number, for better arrangement, you will choose in students with in consecutive numbers. When you choose these m students, you will rearrange their numbers from 1 to m, in the same order with their initial one.
If we divide our students’ heights into k (1<=k<=25) level, experience says that there will exist an best viewing module, represented by an array a[]. a[i] (1<=i<=m)stands for the student’s height with number i. In fact, inside a queue, for every number pair i, j (1<=i,j<=m), if the relative bigger or smaller or equal to relationship between the height of student number i and the height of student number j is the same with that between a[i] and a[j], then the queue is well designed. Given n students’ height array x[] (1<=x[i]<=k), and the best viewing module array a[], how many well designed queues can we make at most?
Input
Multiple cases, end with EOF.
First line, 3 integers, n (1<=n<=10^5) m (1<=m<=n) k(1<=k<=25),
Second line, n students’ height array x[] (1<=x[i]<=k,1<=i<=n);
Third line, m integers, best viewing module array a[] (1<=a[i]<=k,1<=i<=m);
First line, 3 integers, n (1<=n<=10^5) m (1<=m<=n) k(1<=k<=25),
Second line, n students’ height array x[] (1<=x[i]<=k,1<=i<=n);
Third line, m integers, best viewing module array a[] (1<=a[i]<=k,1<=i<=m);
Output
One integer, the maximal amount of well designed queues.
Sample Input
10 5 102 4 2 4 2 4 2 4 2 41 2 1 2 1
Sample Output
1
题意&&分析:字符串匹配的一种变形,要求大小关系匹配上,把比较函数修改一下就可以了。
#include <map> #include <cstdio>#include <cstring>#include <iostream>using namespace std;map <int,int> f;int n,m,k,ans,s[100005],t[100005],l[100005],r[100005],jud[100005],Next[100005];bool cmp(int x,int y){int d = y - x;if(jud[x] >= 0){if(t[d + jud[x]] == t[y]) return true;else return false;}else{if(r[x] >= 0) if(t[d + r[x]] < t[y]) return false;if(l[x] >= 0) if(t[d + l[x]] > t[y]) return false;return true;}}int main(){while(scanf("%d %d %d",&n,&m,&k) == 3){f.clear();for(int i = 0;i < n;i++) scanf("%d",&t[i]);for(int i = 0;i < m;i++) jud[i] = l[i] = r[i] = -1;for(int i = 0;i < m;i++) {scanf("%d",&s[i]);if(f.count(s[i])) jud[i] = f[s[i]];else {map <int,int>::iterator Max = f.lower_bound(s[i]);if(Max != f.end()) r[i] = Max->second;if(Max != f.begin()) l[i] = (--Max)->second;f[s[i]] = i;}}memset(Next,0,sizeof(Next));int now = Next[0] = -1;for(int i = 1;i < m;i++){while(now >= 0 && s[now+1] != s[i]) now = Next[now];if(s[now+1] == s[i]) now++;Next[i] = now;}now = -1,ans = 0;for(int i = 0;i < n;i++){while(now >= 0 && !cmp(now+1,i)) now = Next[now];if(cmp(now+1,i)) now++;if(now == m-1){now = -1;ans++;}}cout<<ans<<endl;}}
0 0
- Hdu-4749 Parade Show
- hdu 4749 Parade Show ( kmp )
- hdu 4749 Parade Show KMP
- hdu 4749 Parade Show(KMP)
- HDU 4749 Parade Show Kmp
- HDU 4749 Parade Show(KMP)
- HDU 4749 Parade Show(暴力水果)
- HDU 4749 Parade Show(KMP变形)
- HDU 4749 Parade Show 数据结构KMP变形
- HDU 4749 Parade Show 相对匹配的KMP
- hdu-4749:Parade Show(kmp模板题)
- Poj 3167 Cow Patterns Hdu 4749 Parade Show (KMP大小关系相同匹配+树状数组)
- 军训选队伍 相对顺序匹配 kmp hdu 4749 Parade Show
- hdu 4749 Parade Show (暴力水 (正解应该是kmp变形))
- HDOJ 4749 - Parade Show 思维...贪心...
- HDOJ 题目 4749 Parade Show(KMP)
- HDOJ4749 Parade Show
- hdu4749 Parade Show(kmp)
- 第一次使用Android Studio时你应该知道的一切配置
- OC单例模式
- Spring如何获取Properties文件的信息
- c++实验5【项目2:数组分离】
- HVR的两种refresh方式对比
- Hdu-4749 Parade Show
- 排序算法
- Spring中事务与aop的先后顺序问题
- web前端开发必知的HTTP通信原理
- ORACLE ROWRUM查询第二条数据如何查询
- Terminating app due to uncaught exception 'CALayerInvalidGeometry' iOS 崩溃
- 在PPT中看不到边框
- 利用if else语句编写程序读取输入,直到#, 用一个感叹号代替每个句号,将原有的每个感叹号用两个感叹号代替,最后报告进行了多少次替代。
- 整型数据转二进制转字符方法(3)