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
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; }
相关文章推荐
- HEU_ Who Is In Front of Me
- hrbeu 哈工程 Who Is In Front of Me
- Who Is In Front of Me(hrbeu1216)
- who is in front of me 解题报告
- ReactJs 报错 Element type is invalid: expected a string (from built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `Me`.
- What is Pay Me to Learn——Google Summer of Code 2013
- Who is in me? -- Freeware on Windows
- The name or security ID (SID) of the domain specified is inconsistent with the trust information for that domain
- - No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing in
- 谁是世上最美的人who is most beautiful one in the word
- iOS Implicit declaration of function XXX is invalid in C99”
- Large Number of Coroutine is possible: Split Stacks in GCC
- Genereate a histogram of how many times each unique word is used in that test
- Android RecyclerView的案例讲述和"The hierarchy of the type ViewHolder is inconsistent"错误解决
- implicit declaration of function "inet_addr" is invaild in C99
- Odd elements at odd and even elements at even positionThis is question asked in one of the interview
- 在 12cR1 数据库中创建测试用户是报 ORA-65096 错误(2c: ORA-65049: creation of local user or role is not allowed in C)
- Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement
- Implicit Declaration of function 'glBindVertexArrayOES' is invalid in c99
- This version of the rendering library is more recent than your version of ADT plug-in. Please update