ZOJ 3932 Handshakes
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 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[n]-s[i]+a[i]);
}
printf("%lld\n",sum);
}
}
return 0;
}
ZOJ 3932 Handshakes的更多相关文章
- ZOJ - 3932 Handshakes 【水】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3932 题意 给出 N 个人,然后 1-N 然后 从 1 - N ...
- ZOJ 3923 Handshakes
水题. 算一下每个人和之前的人握手次数+之后的人和这个人握手次数.取最大值. #include<cstdio> #include<cstring> #include<cm ...
- ZOJ 3932 Deque and Balls
There are n balls, where the i-th ball is labeled as pi. You are going to put n balls into a deque. ...
- Handshakes(思维) 2016(暴力)
Handshakes Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Sta ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
随机推荐
- shell监控脚本实例—监控mysql主从复制
分享一例shell脚本,用于监测mysql数据库的主从复制,有需要的朋友不妨参考学习下. 转自:http://www.jbxue.com/article/14103.html(转载请注明出处) 本节内 ...
- CYQ多数据库链接
枚举名XXXEnum 对应XXXConn的配置数据库链接项 ,不多说,一看就明白!名字空间得要带上数据库名!
- 进程控制函数(1)-getpgid() getpgrp() 获取当前进程的进程组ID
定义:pid_t getpid(void); 表头文件:#include<unistd.h> 说明:getpid()用来取得目前进程的进程识别码, 许多程序利用取到的此值来建立临时文件, ...
- 悦铃文件必须是CCITT A_Law格式的,且没有被压缩
最近在给公司弄来电彩铃,用的是电信的“悦铃”业务,办理过程不想多说了..给了我个网址和账号让我登录,登录界面惨不忍睹,感觉电信根本没有要宣传这项业务的意思,像是粗制滥造外包赶工做出来的.. 当然这不是 ...
- 如何在iOS上实现对HTTPS的支持(转)
原文地址:http://blog.5ibc.net/p/101504.html 首先,需要明确你使用HTTP/HTTPS的用途,因为OSX和iOS平台提供了多种API,来支持不同的用途,官方文档< ...
- ADO.NET数据库应用开发_ExtendedProperties属性
7.5.5 ExtendedProperties属性 ExtendedProperties属性用来获取存储自定义属性的集合.可以在该属性中增加附加的存储信息.它的扩展属性必须是字符串类型.当以XML的 ...
- sama5d36 can0 can1 测试
1 删除/bin/ip 保留/sbin/ip 2 ip link set can0 type can bitrate 125000 ip link set can1 type can bitrate ...
- STM32CubeMX使用方法及功能介绍
推荐 分享一个朋友的人工智能教程,零基础!通俗易懂!希望你也加入到人工智能的队伍中来! http://www.captainbed.net/strongerhuang Ⅰ.写在前面 学习本文之前可以查 ...
- Linux开机启动文件rc.local无法执行怎么办?
rc.local是Linux系统中的一个重要的开机启动文件,每次开机都要执行这个文件.但是有一些用户的Linux系统无法执行这个文件,并导致了一系列的问题.遇到这个问题我们应该怎么办呢? 在Linux ...
- WHERE 子句用于规定选择的标准。
WHERE 子句 如需有条件地从表中选取数据,可将 WHERE 子句添加到 SELECT 语句. 语法 SELECT 列名称 FROM 表名称 WHERE 列 运算符 值 下面的运算符可在 WHERE ...