Description

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
题意:每个人进屋子里坐下,给出每个人和多少人握过手,让你去求一个人可能最多的握手次数;
解题思路:从后往前遍历,a[i]表示第i个人最多握多少次手,然后输出最多的那个,和学姐一起想这个题0.0,好有成就感0.0;
感悟:比赛真是太刺激了~
代码:
#include

#include

#include

using namespace std;

#define maxn 100010

int a[maxn];
int main()

{

    int t;

    scanf("%d",&t);

    while(t--)

    {

        memset(a,0,sizeof(a));

        int n;

        scanf("%d",&n);

        for(int i=0;i

        {

            scanf("%d",&a[i]);

        }

        int ans=0,sum=0;

        for(int i=n-1;i>=0;i--)

        {

            if(a[i])sum++;

            a[i]+=(sum-1);

            ans=max(ans,a[i]);

        }

        printf("%d\n",ans);

    }

    return 0;

}

Handshakes的更多相关文章

  1. Handshakes(思维) 2016(暴力)

    Handshakes Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Sta ...

  2. Codeforces Round #298 (Div. 2) D. Handshakes 构造

    D. Handshakes Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem ...

  3. Codeforces Round #298 (Div. 2) D. Handshakes [贪心]

    传送门 D. Handshakes time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. LeetCode 1259. Handshakes That Don't Cross - Java - DP

    题目链接:https://leetcode-cn.com/problems/handshakes-that-dont-cross/ You are given an even number of pe ...

  5. ZOJ 3923 Handshakes

    水题. 算一下每个人和之前的人握手次数+之后的人和这个人握手次数.取最大值. #include<cstdio> #include<cstring> #include<cm ...

  6. Codeforces Round #298 (Div. 2)--D. Handshakes

    #include <stdio.h> #include <algorithm> #include <set> using namespace std; #defin ...

  7. ZOJ 3932 Handshakes

    Last week, n students participated in the annual programming contest of Marjar University. Students ...

  8. ZOJ - 3932 Handshakes 【水】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3932 题意 给出 N 个人,然后 1-N 然后 从 1 - N ...

  9. 【codeforces 534D】Handshakes

    [题目链接]:http://codeforces.com/contest/534/problem/D [题意] n个人依次进入一个房间; 进进来的人会和房间里面没有组队的人握一次手; (这里的握手只计 ...

随机推荐

  1. shell二位数组——终端字符下降动画

    猜想:Shell支持关联数组,可以利用关联数组模拟二维数组. [验证猜想] #!/bin/bash array[1,1]=1 array[2,1]=2 array[3,1]=3 for i in `s ...

  2. 已被.NET基金会认可的弹性和瞬态故障处理库Polly介绍

    前言 本节我们来介绍一款强大的库Polly,Polly是一种.NET弹性和瞬态故障处理库,允许我们以非常顺畅和线程安全的方式来执诸如行重试,断路,超时,故障恢复等策略. Polly针对对.NET 4. ...

  3. apollo实现c#与android消息推送(三)

    3 实现c#消息推送服务 c#实现消息推送必须引入M2Mqtt.dll,源码 a 连接apache apollo代理服务器的代码.需要引入using uPLibrary.Networking.M2Mq ...

  4. 1289 大鱼吃小鱼 1305 Pairwise Sum and Divide 1344 走格子 1347 旋转字符串 1381 硬币游戏

    1289 大鱼吃小鱼 有N条鱼每条鱼的位置及大小均不同,他们沿着X轴游动,有的向左,有的向右.游动的速度是一样的,两条鱼相遇大鱼会吃掉小鱼.从左到右给出每条鱼的大小和游动的方向(0表示向左,1表示向右 ...

  5. 一脸懵逼学习基于CentOs的Hadoop集群安装与配置

    1:Hadoop分布式计算平台是由Apache软件基金会开发的一个开源分布式计算平台.以Hadoop分布式文件系统(HDFS)和MapReduce(Google MapReduce的开源实现)为核心的 ...

  6. jQuery点击按钮实现div的隐藏和显示切换效果

    <script type="text/javascript"> $(function(){ $('#click_event').click(function(){  i ...

  7. SQL server学习(五)——T-SQL编程之存储过程

    周五了,祝大家周末愉快. 之前一直在写SQL server的分享,今天再来个T-SQL编程中的存储过程. 存储过程 存储过程(procedure)类似于C语言中的函数,用来执行管理任务或应用复杂的业务 ...

  8. 提纲挈领webrtc之vad检测

    顾名思义,VAD(Voice Activity Detection)算法的作用是检测是否是人的语音,它的使用 范围极广,降噪,语音识别等领域都需要有vad检测.vad检测有很多方法,这里我们之介绍一 ...

  9. 数据库表反向生成(一) MyBatis-generator与IDEA的集成

    在Dao层,通过数据库表反向生成,可以节省我们很多的精力,把更多的精力投入复杂的业务中. 数据库表反向生成,指的是通过数据库如mysql中的库表schema生成dao层读写表的基础代码,包括model ...

  10. 【实验吧】Once More

    <?php if (isset ($_GET['password'])) { if (ereg ("^[a-zA-Z0-9]+$", $_GET['password']) = ...