ZOJ 3932 Handshakes
来源:互联网 发布:中英文在线翻译软件 编辑:程序博客网 时间:2024/05/20 02:50
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
#include <iostream>#include <string.h>#include <stdio.h>#include <algorithm>#include <math.h>#include <stdlib.h>using namespace std;#define MAX 100000long long int a[MAX+5];long long int s[MAX+5];long long int b[MAX+5];int t;int n;long long int sum;int main(){ while(scanf("%d",&t)!=EOF) { while(t--) { scanf("%d",&n); sum=0;s[0]=0; //memset(b,0,sizeof(b)); for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); if(a[i]>=1) b[i]=1; else b[i]=0; s[i]=s[i-1]+b[i]; } for(int i=1;i<=n;i++) { sum=max(sum,s[n]-s[i]+a[i]); } printf("%lld\n",sum); } } return 0;}
- ZOJ 3932 Handshakes
- ZOJ 3932 Handshakes
- zoj--3932--Handshakes(水题)
- ZOJ 3932——Handshakes
- ZOJ - 3932 Handshakes (技巧)握手
- ZOJ 3932Handshakes(翻译水题)
- Handshakes
- Codeforces534D:Handshakes
- CFD. Handshakes
- codeforces #298 D. Handshakes
- 【CodeForces 534D】Handshakes
- Codeforces 534D Handshakes(贪心)
- #298 (div.2) D. Handshakes
- URAL 1194. Handshakes (乱搞)
- 【Codeforces 534D】【贪心】Handshakes
- Codeforces 534D Handshakes【贪心】
- zoj 3932
- 534D.Handshakes(Codeforces Round #298(div2))
- 网页前端的异常处理方法、异常处理系统及异常处理服务器
- TCP/IP三次握手与四次挥手
- 找寻路径从根root到节点p的路径函数
- LeetCode #6 ZigZag Conversion C# Solution
- Partitioning Game (SG函数)
- ZOJ 3932 Handshakes
- bfs
- 键盘事件
- 在php中json_encode与json_decode的使用方法
- 用JS获取地址栏参数的方法(超级简单)
- Dubbo高级篇_12_dubbo服务只注册
- poj1328 Radar Installation 贪心
- 最短路
- linux 快捷登录三 expect脚本