HDU 4749 Parade Show(2013 ACM/ICPC Asia Regional Nanjing Online)

 Parade Show

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)

描述

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?

 

输入

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);

 

输出

One integer, the maximal amount of well designed queues.

 

样例输入

10 5 10
2 4 2 4 2 4 2 4 2 4
1 2 1 2 1

样例输出

1

题意:其实题目意思就是根据所给出的a[]模型来判断从n个人中抽出m个连续编号的人组成的队列中有几组符合这个a[]模型,

     a[]模型跟数的值无关,只与相对大小有关,例如样例中的1 2 1 2 1,如果把第一个数1看做低位,则后面四个数可为

     高 低 高 低,故样例中符合条件的5人为2 4 2 4 2,且编号连续,即抽出的编号为1 2 3 4 5,故最后答案为1组。

 

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=100005;


int str[N];
int a[N];

int func(int a[],int b[],int n){
    int i;
    for(i = 0; i < n - 1; i++)
        if((a[i] == a[i + 1]  && b[i] == b[i+1])||
            (a[i] < a[i + 1]  && b[i] < b[i+1])||
            (a[i] > a[i + 1]  && b[i] > b[i+1]))
            continue;
        else
            break;
    if(i == n - 1)
        return 1;
    else
        return 0;
}

int main()
{
    int n,m,k,i,j;
    while(scanf("%d %d %d",&n,&m,&k)!= EOF){
        for(i = 0; i < n; i++)
            scanf("%d",&str[i]);

        for(j = 0; j < m; j++)
            scanf("%d", &a[j]);

        int ans = 0;
        for(i = 0; i < n - m + 1;){
            if(func(a,&str[i],m))
                i = i + m,ans++;
            else
                i++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

 

 

 

posted on 2013-09-21 20:34  落叶伴雨下  阅读(537)  评论(6)    收藏  举报

导航