ZOJ - 3932 Handshakes (技巧)握手
来源:互联网 发布:元胞数组怎么定义 编辑:程序博客网 时间:2024/05/16 01:45
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
230 1 150 0 1 1 1
Sample Output
23
//题意:
有n个人按照次序进场,在后面进来的选手会与在他前面进来的朋友握手(不是朋友的就不会握手),问他们中握手最多的有几次?
//思路:
因为是求最多的,所以如果他们握手的话就让他们都与第一个握手,这样遍历下去就会是第一个人握手次数最多,但是这还有点不严密,因为如果是这种情况0 0 2 的话应该输出2,所以在遍历时还得取最大值。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){int t,n,m,i,j;scanf("%d",&t);while(t--){int a;int k=0;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&a);if(a)k++;k=max(k,a);}printf("%d\n",k);}return 0;}
- ZOJ - 3932 Handshakes (技巧)握手
- zoj--3932--Handshakes(水题)
- ZOJ 3932Handshakes(翻译水题)
- ZOJ 3932 Handshakes
- ZOJ 3932 Handshakes
- ZOJ 3932——Handshakes
- Handshakes
- URAL 1194. Handshakes (乱搞)
- Codeforces 534D - Handshakes(构造,暴力)
- Codeforces Round #298 (Div. 2) D. Handshakes(贪心)
- Codeforces534D:Handshakes
- CFD. Handshakes
- ZOJ 3872 Beauty of Array (技巧)
- ZOJ 1047 Image Perimeters(dfs+技巧)
- 【ZOJ3932 The 16th Zhejiang University Programming ContestF】【水题】Handshakes 每人与之前认识的人握手 最大可能认识人数
- codeforces #298 D. Handshakes
- 【CodeForces 534D】Handshakes
- ZOJ - 3872 Beauty of Array (技巧&模拟)好题
- 用对象数组操作长方柱类
- 关于Java各种流的一点笔记
- iOS----SVProgressHUD
- 萃取(traits)编程技术的介绍和应用
- Solr Getting Started
- ZOJ - 3932 Handshakes (技巧)握手
- 第八周实践项目1.3-用数组作数据成员
- 浅学设计模式之建造者(Buildler Pattern)模式及在android中的应用
- Jetty插件与REST服务
- cocos2dx开发环境搭建
- [Leetcode]258. add digits
- centos 安装 epel
- Linux下的Perforce客户端使用 – P4
- STM32 使用过程注意事项