您的位置:首页 > 其它

2013资格赛——Who Is In Front of Me

2013-08-24 16:25 323 查看
Description
There are N(1<=N<=50000)students stand in a queue.We assume that every can only see the students that are in front of him and taller than him
.

For example, there are 6 students standing in a queue with height of

4 3 1 2 5 2,begining from the front student. In this example, student 3's height is 1, and he can see 2 persons. Student 6, although many students in front are taller than him, but he can only see the student with height of 5.
Now, given the number of students in a queue, and the height of each, can you find the student that can see most persons.
Input
Input contains multiple test cases. The first line is a integer T, the number of cases.The first line of each case is a integer N, the number of students.The second line of each case contains the heights of students from front to back.
Output
For each test case, print a line with a integer M, representing the maximum number of students can someone can see.
Sample Input
2

6

4 3 1 2 5 2

3

2 2 2

Sample Output
2

0
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

const int N=50010;
int arr
,ans
;

int Max(int a,int b)
{
return a>b?a:b;
}

int deal(int n)
{
int i,j,index,max;
index=0,ans[0]=0;
for(i=1;i<n;i++)
{
if(arr[i]<arr[i-1])ans[i]=ans[i-1]+1;
else if(arr[i] < arr[index])
{
for(j = i-1;j >= index;j--)
{
if(arr[j]>arr[i]) {
ans[i] = ans[j] + 1;
break;
}
}
}
else{
ans[i] = 0;
index = i;
}
max = Max(ans[i], max);
}
return max;
}

int main()
{
int t,i,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)scanf("%d",&arr[i]);
printf("%d\n",deal(n));
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐