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 大基础结构,如果说数据是程序的汽油,算法则就是程序的发动机. 什么是数据结构? 指数据在计算机中的存储方式,数据的存储方式会影响到获取数据的便利性. 现实生活中 ...
 
随机推荐
- pyqt 图片(label上显示
			
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' from decimal import * from PyQt4.Q ...
 - Cocoa Pods的安装
			
CocoaPods是用Ruby实现的,要想使用它首先需要有Ruby的环境.幸运的是OS X系统默认已经可以运行Ruby了,因此我们只需执行以下命令: sudo gem install -n /usr/ ...
 - mysql 自己定义存储过程和触发器
			
mysql 自己定义存储过程和触发器 --存储过程示范 DROP PROCEDURE IF EXISTS PRO_TEST; CREATE PROCEDURE PRO_TEST(IN NUM_IN I ...
 - Android开发之去掉标题栏的三种方法,推荐第三种
			
Android:去掉标题栏的三种方法和全屏的三种方法 第一种:一般入门的时候常常使用的一种方法 onCreate函数中增加下面代码: requestWindowFeature(Window.FEATU ...
 - IoC容器Autofac正篇之解析获取(五)
			
解析获取的方式有如下几种: Resolve class Program { static void Main(string[] args) { var builder = new ContainerB ...
 - Web系统如何做到读取客户电脑MAC等硬件信息且兼容非IE浏览器
			
我们在实际Web应用中,可能会遇到“需要限定特定的电脑或用户才能使用系统”的问题. 对于一般情况来说,我们用得最多的可能是使用ActiveX控件的方法来实现,但此方案只适用于IE浏览器.为了能兼容不同 ...
 - SQL server根据值搜表名和字段
			
DECLARE @what varchar(800) SET @what='lll' --要搜索的字符串 DECLARE @sql varchar(8000) DECLARE TableCursor ...
 - icon数目
			
[UIApplication sharedApplication].applicationIconBadgeNumber = currentBadgeValue.integerValue;
 - Emacs下编译C++/C程序<转>
			
1.启动Emacs,在终端输入“emacs&”命令后回车(你也可以输入“emacs”命令,不过当你在使用Emacs的时候,当前终端 就不为你工作了:并且如果你熟练使用Emacs的话也可以输入“ ...
 - JSON的parse()方法
			
JSON方法也可以接受另外的一个参数,作为还原函数. 实例: var book = { title:"JavaScript Learn", author:["wang&q ...