【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 转载还请注明下出处哦,谢谢^_^ https://blog.csdn.net/snowy_smile/article/details/51132407

Intro to the Rust programming language

-
  • 1970年01月01日 08:00

【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...
  • snowy_smile
  • snowy_smile
  • 2016-04-12 13:08:25
  • 497

【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...
  • snowy_smile
  • snowy_smile
  • 2016-04-12 13:13:14
  • 661

The 16th Zhejiang University Programming Contest - E

Huffman Code is a commonly used optimal prefix code. Here is a simple introduction to Huffman Coding...
  • Zafu_Rookie
  • Zafu_Rookie
  • 2016-04-10 18:18:12
  • 183

ZOJ 3932 Handshakes

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3932 题面: Handshakes Time Limit...
  • David_Jett
  • David_Jett
  • 2016-04-10 22:11:41
  • 872

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

Handshakes Time Limit: 2 Seconds      Memory Limit: 65536 KB Last week, n students participate...
  • snowy_smile
  • snowy_smile
  • 2016-04-12 13:11:48
  • 717

The 16th Zhejiang University Programming Contest-

Handshakes Time Limit: 2 Seconds      Memory Limit: 65536 KB Last week, n students participa...
  • NYIST_TC_LYQ
  • NYIST_TC_LYQ
  • 2016-04-13 15:37:57
  • 368

Zhejiang University----A+B

//return a-b; 升序 //return b-a; 降序 /*#include #include   int main(void) {     char name1[81],n...
  • u010899135
  • u010899135
  • 2016-04-07 22:39:31
  • 203

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

#include #include #include #include #include #include #include #include #include #include #include #...
  • snowy_smile
  • snowy_smile
  • 2016-04-12 13:09:16
  • 782

【The 18th Zhejiang University Programming Contest Sponsored by TuSimple - C】Mergeable Stack(list)

链接:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5734 题意:就是一个模拟栈的题,不同的是有一个操作是把第...
  • feng_zhiyu
  • feng_zhiyu
  • 2018-04-15 10:09:56
  • 12
收藏助手
不良信息举报
您举报文章:【ZOJ3932 The 16th Zhejiang University Programming ContestF】【水题】Handshakes 每人与之前认识的人握手 最大可能认识人数
举报原因:
原因补充:

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