ZOJ 3932 Handshakes
2016-04-16 10:25
459 查看
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
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 100000 long 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 -s[i]+a[i]); } printf("%lld\n",sum); } } return 0; }
相关文章推荐
- LeetCode #6 ZigZag Conversion C# Solution
- ZOJ 3932 Handshakes
- SharePoint 2013 网站搜索规则的使用示例
- Caffe 深度学习框架上手教程
- 使用JSSDK集成微信分享遇到的一些坑
- 字节流与字符流的区别详解
- 代码托管和服务功能多元化,看码客帮如何做软件众包
- 整合springMVC,Mybatis的Maven项目框架
- 关于Google Chrome 浏览器的一些命令及用法
- Android天气预报程序(四)
- 银行本票、汇票、支票的区别是什么
- LeetCode 232. Implement Queue using Stacks
- LeetCode——019
- HTML页面关键词随机分布布局
- keil中如何生成bin文件
- SCVMM 2012 SP1 – QuickStart deployment guide
- windows下一分钟配置ngnix实现HLS m3u8点播
- java中日期时间格式与毫秒数的转换
- mysql约束中遇到的一些奇葩版本问题
- 10.--多态、instanceof、内部类、设计模式