zoj--3932--Handshakes(水题)

Handshakes Time Limit: 2 Seconds       Memory Limit: 65536 KB

Last week, n students participated in the annual programming contest of Marjar University. Students are labeled from 1 to n. They came to the competition area one by one, one after another in the increasing order of their label. Each of them went in, and before sitting down at his desk, was greeted by his/her friends who were present in the room by shaking hands.

For each student, you are given the number of students who he/she shook hands with when he/she came in the area. For each student, you need to find the maximum number of friends he/she could possibly have. For the sake of simplicity, you just need to print the maximum value of the n numbers described in the previous line.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n (1 ≤ n ≤ 100000) -- the number of students. The next line contains n integers a1, a2, ..., an (0 ≤ ai < i), where ai is the number of students who the i-th student shook hands with when he/she came in the area.

Output

For each test case, output an integer denoting the answer.

Sample Input

2
3
0 1 1
5
0 0 1 1 1

Sample Output

2

3

题意:有n个人按照顺序进入比赛区域,进去之后可能会有人跟他握手,如果有x人跟他握手说明进来的人有x人是他的朋友,求朋友最多的人有多少个朋友

思路:很简单的贪心,每次进来的人如果有人跟他握手,我们就断定一定有朋友最多的那个人跟他握手,可能会出现0 0 2这种情况,所以每次要判断最大值是否会变化

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n;
		scanf("%d",&n);
		int maxx=0,a;
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a);
			if(a) maxx++;
			maxx=max(maxx,a);
		}
		printf("%d\n",maxx);
	}
	return 0;
} 


你可能感兴趣的:(zoj--3932--Handshakes(水题))