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. PuTsangTo-单撸游戏开发01 Flag与计划

    先立下flag,至少1年之内坚持并2年之内完成自己的一个梦想--游戏开发. 没有参加培训也不打算参加培训,就纯靠业余时间自学并用自己的思路完成一整套游戏体系.做出此决心时也已经做好准备烂尾了,但是有种 ...

  2. ioc(Inversion of Control)控制反转和DI

    ioc意味着将你设计好的交给容器控制,而不是传统在你的对象中直接控制 谁控制了谁:传统的javaSE程序设计,我们直接在对象内部通过new进行创建对象,是程序主动去创建依赖对象:而ioc是有专门一个容 ...

  3. java集合系列——java集合概述(一)

    在JDK中集合是很重要的,学习java那么一定要好好的去了解一下集合的源码以及一些集合实现的思想! 一:集合的UML类图(网上下载的图片) Java集合工具包位置是java.util.* 二:集合工具 ...

  4. hdu 2609 How many 最小表示法

    How many Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. 推荐系统相关算法(1):SVD

    假如要预测Zero君对一部电影M的评分,而手上只有Zero君对若干部电影的评分和风炎君对若干部电影的评分(包含M的评分).那么能预测出Zero君对M的评分吗?答案显然是能.最简单的方法就是直接将预测分 ...

  6. Ubuntu 16安装GPU版本tensorflow

    pre { direction: ltr; color: rgb(0, 0, 0) } pre.western { font-family: "Liberation Mono", ...

  7. STM8学习

    今天正式学习STM8,用的是风驰STM8S208R开发板. 在编译例程遇到了如下这样的问题. " #error clnk debug\stm8s_demo.lkf:47 can't open ...

  8. 由 System.arraycopy 引发的巩固:对象引用 与 对象 的区别

    作者:林冠宏 / 指尖下的幽灵 掘金:https://juejin.im/user/587f0dfe128fe100570ce2d8 博客:http://www.cnblogs.com/linguan ...

  9. 【转】python os.popen 超时问题

    python 版本 2.5.4 (在高版本python中提倡使用 subprocess.Popen 取代 os.popen) os.popen 会出现过长时间等待导致阻塞问题, 解决方法如下: [py ...

  10. 使用VLC创建组播流

    vlc既是一个播放器,又可以成为一个流媒体服务器.最近需要做udp组播播放相关的东西,需要先在本地搭建一个udp组播服务器,因为机器上本来就装有vlc,所以就用它了. 第一步: 点击媒体->流 ...