zoukankan      html  css  js  c++  java
  • ZOJ

    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 <cstdio>
    #include <iostream>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <queue>
    #include <algorithm>
    #include <map>
    using namespace std;
    #define ll long long
    const int inf = 0xffffff;
    const int maxn = 1e5+8;
    int t, n, miao, sum;
    int main()
    {
        scanf("%d", &t);
        while(t--)
        {
            scanf("%d", &n);
            sum = 0;
            while(n--)
            {
                scanf("%d", &miao);
                if(miao>sum)
                    sum = miao;
                else if(miao>0) sum++;
            }
            printf("%d
    ", sum);
        }
        return 0;
    }
  • 相关阅读:
    Wannafly #4 F 线路规划
    PKUWC2018 随机算法
    noip模拟赛
    php 正则判断是否是手机号码 最新
    Onethink上传服务器后登录不了的问题
    【php中的curl】php中curl的详细解说
    50种网站引流量方式
    mysql ERROR 1045 (28000): 错误解决办法
    织梦DEDE分类信息实现联动筛选(支持多条件多级选项)解决方案
    dedecms新增联动类别后的使用方法
  • 原文地址:https://www.cnblogs.com/RootVount/p/10706272.html
Copyright © 2011-2022 走看看