首页 > 其他分享 >ZOJ - 3932 Handshakes (技巧)握手

ZOJ - 3932 Handshakes (技巧)握手

时间:2023-06-08 14:04:07浏览次数:51  
标签:int ZOJ number 3932 she each Handshakes 握手 he

Time Limit: 2000MS

 

Memory Limit: 65536KB

 

64bit IO Format: %lld & %llu

ZOJ - 3932


Handshakes



Submit Status




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






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;
}





标签:int,ZOJ,number,3932,she,each,Handshakes,握手,he
From: https://blog.51cto.com/u_16079508/6439503

相关文章

  • bzoj4399: 魔法少女LJJ
    bzoj4399:魔法少女LJJ题目描述在森林中见过会动的树,在沙漠中见过会动的仙人掌过后,魔法少女LJJ已经觉得自己见过世界上的所有稀奇古怪的事情了LJJ感叹道“这里真是个迷人的绿色世界,空气清新、淡雅,到处散发着醉人的奶浆味;小猴在枝头悠来荡去,好不自在;各式各样的鲜花争相开放,......
  • bzoj 1007: [HNOI2008]水平可见直线(模拟栈)
    http://www.lydsy.com/JudgeOnline/problem.php?id=10071007:[HNOI2008]水平可见直线TimeLimit: 1Sec  MemoryLimit: 162MBSubmit: 7644  Solved: 2922[Submit][Status][Discuss]Description在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往......
  • bzoj1001 [BeiJing2006]狼抓兔子(网络流dinic算法||最短路spfa)
    http://www.lydsy.com/JudgeOnline/problem.php?id=10011001:[BeiJing2006]狼抓兔子TimeLimit: 15Sec  MemoryLimit: 162MBSubmit: 24017  Solved: 6068[Submit][Status][Discuss]Description现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓......
  • BZOJ1503(Splay)
    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1503 #include<iostream>#include<string.h>#include<stdio.h>usingnamespacestd;structNode{intval,size,cnt,lazy;Node*pre,*ch[2];Node(){size=lazy......
  • ZOJ - 4069(2018 青岛现场赛 L) - 指数型生成函数
    题目链接:https://vjudge.net/problem/ZOJ-4069 解题思路:1.n个点组成环的不同种类数是(n-1)!/2;n个点组成一条链的不同种类数是n!/2,特别的n==1时种类数为1。用指数型生成函数表示k个点形成链的种类:1/2(2x+2!*x^2/2!+3!*x^3/3!+4!*x^4/4!+..+n!*x^n/n!)=1/2(2*x+x^2+x^3+x^4+......
  • 2018ACM浙江省赛 ZOJ 4029 Now Loading!!!(二分)
    NowLoading!!!TimeLimit: 1Second     MemoryLimit: 131072KBDreamGridhas  integers .DreamGridalsohas foragivennumber ,where , .InputTherearemultipletestcases.Thefirstlineofinputisaninteger Thefirstlinecon......
  • ZOJ 4020 Traffic Light(走迷宫变形)
    传送门我感觉就是一个走迷宫的题,只不过这个的墙是变化的。但是因为一直在0-1之间转换,所以把走到当前位置的步数进行判断,如果是奇数就把当前位置的灯状态改变,偶数不用处理,然后就是基本的搜索了。#include<bits/stdc++.h>usingnamespacestd;constintmaxn=1e5+10;vector<int>......
  • ZOJ 3960 What Kind of Friends Are You?(模拟)
    传送门给你几个人,然后下i行对应的是回答出来第i个问题的人,最后询问回答出来了哪几个问题的是谁。用一个map,存名字和数字,回答出的问题编号也转化为2进制,然后转化为10进制,这样的话每个人回答出的问题就对应的是一个数字,询问的时候也把2进制的串转化为10进制,这样的话比对就比较方便。......
  • ZOJ 3961 Let's Chat
    传送门给你A的区间和B的区间,然后问你重合的区间。答案就是求重合的区间长度-m+1的值。因为数据量不大,所以就让A的每个区间都对B的区间进行匹配,然后求和就可以了。这就是一种暴力。#include<bits/stdc++.h>usingnamespacestd;constintmaxn=150;typedefpair<int,int>pq;p......
  • ZOJ 3958 Cooking Competition
    传送门也没什么好说的,就根据题意说的写就完事儿了。#include<bits/stdc++.h>usingnamespacestd;intmain(){//freopen("in.txt","r",stdin);cin.tie(0);cout.tie(0);intt,ko,to;cin>>t;while(t--){intn;......