Handshakes
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的更多相关文章
- Handshakes(思维) 2016(暴力)
Handshakes Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Sta ...
- Codeforces Round #298 (Div. 2) D. Handshakes 构造
D. Handshakes Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/problem ...
- Codeforces Round #298 (Div. 2) D. Handshakes [贪心]
传送门 D. Handshakes time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 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 ...
- ZOJ 3923 Handshakes
水题. 算一下每个人和之前的人握手次数+之后的人和这个人握手次数.取最大值. #include<cstdio> #include<cstring> #include<cm ...
- Codeforces Round #298 (Div. 2)--D. Handshakes
#include <stdio.h> #include <algorithm> #include <set> using namespace std; #defin ...
- ZOJ 3932 Handshakes
Last week, n students participated in the annual programming contest of Marjar University. Students ...
- ZOJ - 3932 Handshakes 【水】
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3932 题意 给出 N 个人,然后 1-N 然后 从 1 - N ...
- 【codeforces 534D】Handshakes
[题目链接]:http://codeforces.com/contest/534/problem/D [题意] n个人依次进入一个房间; 进进来的人会和房间里面没有组队的人握一次手; (这里的握手只计 ...
随机推荐
- CSDN博客新手使用方案
CSDN博客简易使用 在CSDN上写博客,总是遇到很多问题,虽然这些问题很简单,但是对于新手来说,缺经常遇到,因此写篇博客记载. 一.CSDN的博客如何上传图片 如果有现成 ...
- 循环语句for,while,until,select
循环 *循环执行 将某代码段重复运行多次 重复运行多少次: 循环次数事先已知 循环次数事先未知 有进入条件和退出条件 *常见的循环语句有for,while,until for循环 for 变量名 n ...
- JAVA_String、StringBuilder、StringBuffer区别
String.StringBuilder.StringBuffer均为字符串 类 需要注意的一些问题 String StringBuilder StringBuffer 一旦创建,不能对其内容进行更改 ...
- MMORPG战斗系统随笔(一)
前言 很久没有更新博客,中间迁移过一次博客,后来一直忙于项目的开发,忙的晚上回去没时间写博客,周日又要自我调整一下,所以空闲了很久没有继续写博客.最近终于慢慢放慢节奏,项目也快上线了,可以有空写一些个 ...
- java从命令行接收多个数字,求和程序分析
问题:编写一个程序,此程序从命令行接收多个数字,求和之后输出结果. 1.设计思想 (1)声明两个变量接收输入的字符串 (2)将字符串转换成int类型 (3)输出求和 2.程序流程图 3.源程序代码 i ...
- 分布式系统中生成全局ID的总结与思考
世间万物,都有自己唯一的标识,比如人,每个人都有自己的指纹(白夜追凶给我科普的,同卵双胞胎DNA一样,但指纹不一样).又如中国人,每个中国人有自己的身份证.对于计算机,很多时候,也需要为每一份数据生成 ...
- ClassLoader类加载机制&&JVM内存管理
一.ClassLoader类加载机制 在java中类加载是遵循委派双亲加载的:通过调用loadClass方法逐级往上传递委派加载请求,当找不到父ClassLoader时调用其findClass方法尝试 ...
- Sets 比赛时想错方向了。。。。 (大数不能处理负数啊)
Sets Time Limit: 6000/3000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus P ...
- 架构师之路-在Dubbo中开发REST风格的远程调用
架构师之路:从无到有搭建中小型互联网公司后台服务架构与运维架构 http://www.roncoo.com/course/view/ae1dbb70496349d3a8899b6c68f7d10b 概 ...
- webpack 的使用2
实际项目中的配置 要加__dirname 不然会报错 注意path /dist 前不要加点 结果 将两个文件打包在一起 结果 传入对象 并且单独打包 name为key 加上本次打包的hash has ...