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. 用vue开发一个app(3,三天的成果)

    前言 一个vue的demo 源码说明 项目目录说明 . |-- config // 项目开发环境配置 | |-- index.js // 项目打包部署配置 |-- src // 源码目录 | |-- ...

  2. css预处理器less和scss之sass介绍(二)

    本来打算整理jQuery Mobile来着,但是没有研究明白,所以接着上个周的继续介绍... [scss中的基础语法]   1.scss中的变量 ①声明变量:$变量名:变量值 $width:100px ...

  3. Spark任务流程笔记

    Spark学习笔记总结 02. Spark任务流程 1. RDD的依赖关系 RDD和它依赖的父RDD(s)的关系有两种不同的类型,即窄依赖(narrow dependency)和宽依赖(wide de ...

  4. js两个叹号的使用

    1.浏览器判断空和未定义以及零时返回的值如下: alert(undefined)  //undefined alert(null)  //null alert(0)  //0 2.有时为了便于下一步判 ...

  5. Linux的硬盘使用情况、挂载、SSD挂载(查看df -h不能看到的卷)

    linux上的盘和window的有区别,磁盘空间必须挂载在目录上,要不然没用 对与新增的硬盘.SSD固态硬盘.挂载到linux上的操作如下: df -h      #显示目前在Linux系统上的文件系 ...

  6. Opengl4.5 中文手册—F

    索引 A      B    C      D     E     F     G H      I     J      K     L     M     N O      P    Q      ...

  7. Linux入门之常用命令(13) date

    在linux shell编程中,经常用到日期的加减运算 以前都是自己通过expr函数计算,很麻烦 其实date命令本身提供了日期的加减运算 非常方便.例如:得到昨天的时间date +%Y%m%d -- ...

  8. Sequence query 好题啊

    Sequence query Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Subm ...

  9. git gc -- 压缩历史信息

    格式:           git gc  [选项] <path> 选项 git commit -a 提交所有改动的文件(a -- all) NOTE: XX 举例 压缩历史消息 git ...

  10. Message Queuing(MSMQ)

    一.前言 MicroSoft Message Queuing(微软消息队列)是在多个不同的应用之间实现相互通信的一种异步传输模式,相互通信的应用可以分布于同一台机器上,也可以分布于相连的网络空间中的任 ...