Handshakes

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

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 a1a2, ..., 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
题解:水题,就是参加运动会,依次进来n个人,每来一个都有朋友给他握手,问最多有多少个朋友,有两种可能;
一:只要有人给其握手,那么把大于等于1的数字个数加起来,相当于第一个人进来给他们都握手。
二:当前进来的人给其握手的最大值;
比较第一和第二种情况的最大值就好了;
代码:
#include<cstdio>
#include<cstring> #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long a,maxx=,n;
scanf("%lld",&n);
for(int i=;i<n;i++)
{
scanf("%lld",&a);
if(a>)
maxx++;
maxx=max(maxx,a);
}
printf("%lld\n",maxx);
}
return ;
}
2016

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

In mathematics, a polygonal number is a number represented as dots or pebbles arranged in the shape of a regular polygon. The dots are thought of as alphas (units). These are one type of 2-dimensional figurate numbers. The following picture shows how triangular numbers, square numbers, pentagonal numbers and hexagonal numbers represented as dots arranged in the shape of corresponding regular polygon.

2016 is not only a leap year but also a triangular and hexagonal year. If you are patient enough, you can count the number of the dots in the left triangle or in the right hexagon in the following picture. The number of dots in each shape is 2016.

Therefore, 2016 is a triangular-hexagonal-leap year. The previous triangular-hexagonal-leap year is 1540 and the next is 2556. So living to see 2016 is very rare experience.

You task is to list the triangular-hexagonal-leap years from 2016 to 990528. 990528 is also a triangular-hexagonal-leap year.

Input

This problem has no input.

Output

Please print each triangular-hexagonal-leap year in increasing order.

For example, if you are asked to list the triangular-hexagonal-leap years from 780 to 2556, the output should be:

 780
1128
1540
2016
2556

Sample Output

2016
2556
... <-- some lines are skipped
990528
题解:就是找2016--990528之间的闰年,满足三角形以及六边形的那两个公式的年份;
n(n + 1)/2, n(2n - 1);
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdlib>
using namespace std;
const int INF = 0x3f3f3f3f;
bool triang(int x){
int t = (int)sqrt(1.0 + * x);
if(t * t != + * x)
return false;
if((t - ) % != )
return false;
// if(x == 2016)printf("%d %d %d\n",t, t * t, 1 + 8 * x);
return true;
}
bool hex(int x){
int t = (int)sqrt(1.0 + * x);
// if(x == 2016)printf("%d %d %d\n",t, t * t, 1 + 8 * x);
if(t * t != + * x)
return false;
if((t + ) % != )
return false;
return true;
}
bool leap(int x){
if(x % == || (x % == && x % != ))
return true;
else
return false;
}
int main(){
for(int i = ; i <= ; i++){
if(leap(i) && triang(i) && hex(i))
printf("%d\n", i);
}
return ;
}

Handshakes(思维) 2016(暴力)的更多相关文章

  1. Fleecing the Raffle(NCPC 2016 暴力求解)

    题目: A tremendously exciting raffle is being held, with some tremendously exciting prizes being given ...

  2. codeforces 466B Wonder Room(思维,暴力)

    题目 参考了别人的博客,百度来的博客 #include<iostream> #include<string> #include<stdio.h> #include& ...

  3. Codeforces Round #336 (Div. 2)【A.思维,暴力,B.字符串,暴搜,前缀和,C.暴力,D,区间dp,E,字符串,数学】

    A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  4. 2017多校第8场 HDU 6138 Fleet of the Eternal Throne 思维,暴力

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6138 题意:给了初始区间[-1,1],然后有一些操作,可以r加上一个数,l减掉一个数,或者同时操作,问 ...

  5. codeforces1073d Berland Fair 思维(暴力删除)

    题目传送门 题目大意:一圈人围起来卖糖果,标号从1-n,每个位置的糖果都有自己的价格,一个人拿着钱从q开始走,能买则买,不能买则走到下一家,问最多能买多少件物品. 思路:此题的关键是不能买则走到下一家 ...

  6. Codeforces Round #588 (Div. 2)C(思维,暴力)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int a[27],b[27];int vis ...

  7. Python ---- KMP(博文推荐+代码)

    既解决完后宫问题(八皇后问题)后,又利用半天的时间完成了著名的“看毛片”算法——KMP.对于初学者来说这绝对是个大坑,非常难以理解. 在此,向提出KMP算法的三位大佬表示诚挚的敬意.!!!牛X!!! ...

  8. Involuting Bunny! (2021.8)

      CF1555F & Submission.   Tags:「A.生成树」「B.Tricks」   分类处理询问的 trick:连接两个连通块的边显然合法,先用这些边构建生成森林.发现每条边 ...

  9. Python <算法思想集结>之初窥基础算法

    1. 前言 数据结构和算法是程序的 2 大基础结构,如果说数据是程序的汽油,算法则就是程序的发动机. 什么是数据结构? 指数据在计算机中的存储方式,数据的存储方式会影响到获取数据的便利性. 现实生活中 ...

随机推荐

  1. 【转】invokeRequired属性和 invoke()方法

    C#中禁止跨线程直接访问控件,InvokeRequired是为了解决这个问题而产生的,当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它. 此时它将会在内部调用n ...

  2. Oracle varchar 字段排序问题

    数据库字段: 想要的结果: 实际查询的结果: 解决方法:使用CAST函数把varchar2转为int类型 order by CAST(CODE AS INTEGER)

  3. yii使用寻呼功能

    CDbCriteria这是类包使用,包是yii自带专门用来处理类似分类这种功能的. 而我们使用yii框架然后调用这种方法会起到事半功倍的效果,会发现使用这个可以节省非常多的时间.让你高速的使用PHP中 ...

  4. Dalvik虚拟机简要介绍和学习计划

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8852432 我们知道,Android应用程序是 ...

  5. 又一道软通动力7K月薪面试题——银行业务调度系统

    后期补充:网友对我诟病最多的就是我帮学生做面试题,说这是小偷和骗子行为,在此,我对自己给学员做面试题做出例如以下解释:  (1)学员拿着面试题来找老师,学生也事先思考和尝试后实在没有办法,又求职心切才 ...

  6. map的类型映射

    以下是使用STL中map类型,对类型的转换示例,主要可以解决的问题,也就是一般的类型之间的相互转换,可以较好的解决相关的问题. 以下是C++源码,比较简短,容易理解的. #include " ...

  7. flexible.js字体大小诡异现象解析及解决方案

    最近在做一个手机端页面时,遇到了一个奇怪的问题:字体的显示大小,与在CSS中指定的大小不一致.大家可以查看这个Demo(记得打开Chrome DevTools). 就如上图所示,你可以发现,原本指定的 ...

  8. js获取名字为XX的标签

    $("input[name='XX']"); <input name="address_select" type="radio" va ...

  9. nodejs之简介及安装(一)

    @[nodejs|个人学习笔记] nodejs简介 什么是node.js Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境. 参考网站 一.nodejs.cn 二 ...

  10. Eclipse安装Vim——viPlugin插件

    1.下载viPlugin: http://www.viplugin.com/files/viPlugin_2.14.0.zip 2.安装 解压后有两个文件夹: features 和 plugins 把 ...