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个人依次进入一个房间; 进进来的人会和房间里面没有组队的人握一次手; (这里的握手只计 ...
随机推荐
- Java开发中遇到的问题
head丢失 html的dtd不对 Integer数据类型 使用==比较 这个肯定错(事后才知道) sql语句处理分组的时候,在本地服务使用没问题,在服务器上出现sql异常 group by语句规范, ...
- 【转】Spark Streaming和Kafka整合开发指南
基于Receivers的方法 这个方法使用了Receivers来接收数据.Receivers的实现使用到Kafka高层次的消费者API.对于所有的Receivers,接收到的数据将会保存在Spark ...
- U盘中毒无限蓝屏重启的解决办法
开门见山,这个帖子只针对U盘中毒导致的以下两种症状: 1.win10系统无法进入并且要求初始化,卸载所有第三方应用 2.win7系统无限蓝屏重启): 其他的硬件故障不在本次讨论范围之内. 说明以下.上 ...
- Uva 3708 Graveyard
题意:在周长为10000的圆上等距分布着n个雕塑.现在又有m个新雕塑加入(位置可以随意放),希望所有n+m个雕塑在圆周上均匀分布. 这就需要移动其中一些原有的雕塑.要求n个雕塑移动的距离最小. (2& ...
- apache一个ip多个端口虚拟主机
1.打开httpd.conf,查找Listen:80,在下面一行加入Listen:8080:2.查找#Include conf/extra/httpd-vhosts.conf,将此行前面的#去掉:3. ...
- Jquery几行代码解决跟随屏幕滚动DIV
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- SQLyog快捷键汇总
Ctrl+M 创建一个新的连接Ctrl+N 使用当前设置新建连接Ctrl+F4 断开当前连接 对象浏览器 F5 刷新对象浏览器(默认)Ctrl+B 设置焦点于对象浏览器 SQL 窗 ...
- Java中public,protected,default,private的访问权限问题(简明扼要)
import packa.*;//导入了packa包中所有的类.(不包括包中的子包)一般不会用,用哪个导入哪个. 导包的原则:用到哪个类,就导入哪个类.所有字母都小写. 权限列表: public ...
- 吾八哥学Python(五):Python基本数学运算
今天我们学习Python里的基本数学运算方法,还是通过例子来练习吧! 加减乘除求余 #加法 print(12+34) #减法 print(30-10.0) #乘法 print(3*5) #除法 pri ...
- C# 格式化字符串
C#字符串使用{}来格式化 {引索,宽度:格式} 格式后面加数字保留位数 格式 C人民币 {0,10:C10} <script type="text/javascript"& ...