Handshakes(思维) 2016(暴力)
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 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
题解:水题,就是参加运动会,依次进来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 ;
}
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(暴力)的更多相关文章
- Fleecing the Raffle(NCPC 2016 暴力求解)
题目: A tremendously exciting raffle is being held, with some tremendously exciting prizes being given ...
- codeforces 466B Wonder Room(思维,暴力)
题目 参考了别人的博客,百度来的博客 #include<iostream> #include<string> #include<stdio.h> #include& ...
- 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 ...
- 2017多校第8场 HDU 6138 Fleet of the Eternal Throne 思维,暴力
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6138 题意:给了初始区间[-1,1],然后有一些操作,可以r加上一个数,l减掉一个数,或者同时操作,问 ...
- codeforces1073d Berland Fair 思维(暴力删除)
题目传送门 题目大意:一圈人围起来卖糖果,标号从1-n,每个位置的糖果都有自己的价格,一个人拿着钱从q开始走,能买则买,不能买则走到下一家,问最多能买多少件物品. 思路:此题的关键是不能买则走到下一家 ...
- Codeforces Round #588 (Div. 2)C(思维,暴力)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int a[27],b[27];int vis ...
- Python ---- KMP(博文推荐+代码)
既解决完后宫问题(八皇后问题)后,又利用半天的时间完成了著名的“看毛片”算法——KMP.对于初学者来说这绝对是个大坑,非常难以理解. 在此,向提出KMP算法的三位大佬表示诚挚的敬意.!!!牛X!!! ...
- Involuting Bunny! (2021.8)
CF1555F & Submission. Tags:「A.生成树」「B.Tricks」 分类处理询问的 trick:连接两个连通块的边显然合法,先用这些边构建生成森林.发现每条边 ...
- Python <算法思想集结>之初窥基础算法
1. 前言 数据结构和算法是程序的 2 大基础结构,如果说数据是程序的汽油,算法则就是程序的发动机. 什么是数据结构? 指数据在计算机中的存储方式,数据的存储方式会影响到获取数据的便利性. 现实生活中 ...
随机推荐
- Ant-进阶
Ant的概念 可能有些读者并不连接什么是Ant以及入可使用它,但只要使用通过Linux系统得读者,应该知道make这个命令.当编译Linux内核及一些软件的源程序时,经常要用这个命令.Make命令其实 ...
- Impala与Hive的比較
1. Impala架构 Impala是Cloudera在受到Google的Dremel启示下开发的实时交互SQL大数据查询工具,Impala没有再使用缓慢的Hive+MapReduce批 ...
- input输入字母自动大小写转换
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- samba服务器加入域控主机所需要修改的配置文件
samba服务器加入域控主机,成为域成员,当用户访问samba服务器上的共享文件时,直接到域控主机上进行认证.samba服务器上不需要像先前一样创建系统用户,创建samba用户及密码. 1.安装环境( ...
- long类型在C#和C++中的异同
C++中long是32位的整数类型. 而在C#中long是64位的,对应包装类型是Int64,int对应Int32. 显然C++中的long类型,而应该对应C#中的int, C#调用C++ ...
- .responsiveSlides参数
$(".rslides").responsiveSlides({ auto: true, // Boolean: Animate automatically, true or fa ...
- C#控制条码打印机 纸张大小,间距,绘制内容(所有条码打印机通用)
其他条码知识 请访问:http://www.ybtiaoma.com ,本文仅供参考,请勿转载,谢谢 using System; using System.Drawing; using System. ...
- 安卓tabhost和子Activity通信方法
发现很多同学在问这个问题 1个tabhost对应的类假设是T,假设包含2个子tab,每个是1个activity,假设叫a,b,对应的类假设是A和B 那么有这几个问题 1.a如何调用b的方法,或者说发送 ...
- No.1_1 java语言基础_学习笔记
import java.util.Scanner; public class HelloWorld { static final double PI=3.14; static int x=125; / ...
- sshfs远程文件系统挂载
注意:转载请注明出处: http://www.programfish.com/blog/?p=145 sshfs简介: 一种通过SSH协议访问远程文件系统的用户空间文件系统.可以把远程主机上的文件系统 ...