【ZOJ3932 The 16th Zhejiang University Programming ContestF】【水题】Handshakes 每人与之前认识的人握手 最大可能认识人数

原创 2016年04月12日 13:11:48
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

Author: LIN, Xi
Source: The 16th Zhejiang University Programming Contest


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 1e5+10, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int casenum, casei;
int n;
int a[N], sum[N];
int main()
{
	scanf("%d", &casenum);
	for (casei = 1; casei <= casenum; ++casei)
	{
		scanf("%d", &n);
		for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);
		sum[n + 1] = 0;
		for (int i = n; i >= 1; i--)sum[i] = sum[i + 1] + (a[i]>0);
		int ans = 0;
		for (int i = 1; i <= n; ++i)gmax(ans, a[i] + sum[i + 1]);
		printf("%d\n", ans);
	}
	return 0;
}
/*
【题意】
n(1e5)个人依次进房间,每个人会与之前在房间的所有人中认识的握手。
告诉你每个人与多少人握了手,让你输出哪个人可能认识的人最多,输出这个最多认识人数。

【类型】
水题

【分析】
直接统计后缀非0数的个数
gamx(ans,a[i]+后缀非0数个数)

【时间复杂度&&优化】
O(n)

*/


版权声明:题解中哪里写错请一定要指出来QwQ 转载还请注明下出处哦,谢谢^_^

相关文章推荐

【ZOJ3927 The 16th Zhejiang University Programming ContestA】【水题】Programming Ability Test 简单求和比大小

Programming Ability Test Time Limit: 2 Seconds      Memory Limit: 65536 KB Programming Ability Te...

【ZOJ3935 The 16th Zhejiang University Programming ContestI】【暴力 水题】2016 找寻triangular-hexagonal-leap y

2016 Time Limit: 2 Seconds      Memory Limit: 65536 KB In mathematics, a polygonal number is a...

【ZOJ3931 The 16th Zhejiang University Programming ContestE】【小根堆 哈夫曼树 DP】Exact Compression 建立哈弗曼树并编码0

#include #include #include #include #include #include #include #include #include #include #include #...

【ZOJ3933 The 16th Zhejiang University Programming ContestG】【费用流】Team Formation 最多组队条件下女

Team Formation Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge For an u...

【ZOJ3930 The 16th Zhejiang University Programming ContestD】【模拟】Dice Notation 表达式转化标准格式

Dice Notation Time Limit: 2 Seconds      Memory Limit: 65536 KB ... I want to get some wat...

【ZOJ3929 The 16th Zhejiang University Programming ContestC】【DP】Deque and Balls n个数放入双端队列2^n种方案有多少个位置

Deque and Balls Time Limit: 2 Seconds      Memory Limit: 65536 KB There are n balls, where t...

【ZOJ3941 The 13th Zhejiang Provincial Collegiate Programming ContestF】【贪心 暴力】Kpop Music Party n段part

Kpop Music Party Time Limit: 2 Seconds      Memory Limit: 65536 KB Marjar University ofte...

【ZOJ3947 The 13th Zhejiang Provincial Collegiate Programming ContestL】【水题】Very Happy Great BG 简单求和

Very Happy Great BG Time Limit: 2 Seconds      Memory Limit: 65536 KB The summer training...

【ZOJ3956 The 17th Zhejiang University Programming Contest I】【01背包】Course Selection System 公式最大化

Course Selection System Time Limit: 1 Second      Memory Limit: 65536 KB There are n courses in th...

【ZOJ3948 The 17th Zhejiang University Programming Contest A】【暴力 or 讨论】Marjar Cola 瓶盖饮料换可乐

Marjar Cola Time Limit: 1 Second      Memory Limit: 65536 KB Marjar Cola is on sale now! In or...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:【ZOJ3932 The 16th Zhejiang University Programming ContestF】【水题】Handshakes 每人与之前认识的人握手 最大可能认识人数
举报原因:
原因补充:

(最多只允许输入30个字)