British astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, he has even defined an "Eddington number", E -- that is, the maximum integer E such that it is for E days that one rides more than E miles. Eddington's own E was 87.
Now given everyday's distances that one rides for N days, you are supposed to find the corresponding E (≤N).
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (≤105), the days of continuous riding. Then N non-negative integers are given in the next line, being the riding distances of everyday.
Output Specification:
For each case, print in a line the Eddington number for these N days.
Sample Input:
10
6 7 6 9 3 10 8 2 7 8
Sample Output:
6
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <set>
using namespace std; const int maxn=;
int dis[maxn]; int main(){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++){
int id;
scanf("%d",&id);
if(id>)id=;
dis[id]++;
}
int cnt=;
int i;
for(i=;i>=;i--){
if(cnt>=i)break;
cnt+=dis[i];
}
printf("%d",i);
}
注意点:其实就是找最大的满足条件的数,条件就是大于指定数的个数是否大于这个数。但是注意从后往前遍历增加时,不能输出大于它的个数,要输出指定数,还有超过100000的数要特殊处理
PAT A1117 Eddington Number (25 分)——数学题的更多相关文章
-
【PAT甲级】1117 Eddington Number (25分)
题意: 输入一个正整数N(<=100000),接着输入N个非负整数.输出最大的整数E使得有至少E个整数大于E. AAAAAccepted code: #define HAVE_STRUCT_TI ...
-
PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)
1024 Palindromic Number (25 分) A number that will be the same when it is written forwards or backw ...
-
PTA PAT排名汇总(25 分)
PAT排名汇总(25 分) 计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科 ...
-
PAT甲级——A1117 Eddington Number【25】
British astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, h ...
-
PAT 1117 Eddington Number [难]
1117 Eddington Number (25 分) British astronomer Eddington liked to ride a bike. It is said that in o ...
-
PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)
1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive int ...
-
PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
-
PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)
1032 Sharing (25 分) To store English words, one method is to use linked lists and store a word let ...
-
PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*
1029 Median (25 分) Given an increasing sequence S of N integers, the median is the number at the m ...
随机推荐
-
命令行操作svn和git和git
前几天在写代码的时候电脑突然坏掉,老大交代的任务没完成,非常痛恨自己用svn或者git保存代码,相信很多程序员遇到过,硬盘坏掉,存在硬盘中的代码丢失,无法找回的问题,svn和git可谓程序员界的福音, ...
-
Redis教程(十四):内存优化介绍
转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/142.html 一.特殊编码: 自从Redis 2.2之后,很多数据类型都 ...
-
使用git做服务器端代码的部署
传统部署方案 windows 远程桌面 FTP/SFTP 登录服务器pull github代码 Phing(PHP专业部署工具) git 自动部署流程图 服务器端准 ...
-
SQL性能优化的思路建议
如何在 Oracle数据库里写出高质量的SQL语句,如何在Oracle数据库里对有性能问题的SQL做诊断和调整,这是DBA们在ORACLE数据库实践中不可避免的难题.下面就让我们来分析一下拿到一条问题 ...
-
Nginx 限流
原文链接:http://colobu.com/2015/10/26/nginx-limit-modules/?utm_source=tuicool&utm_medium=referral 电商 ...
-
ASP.NET没有魔法——ASP.NET MVC路由
之前的文章中介绍了My Blog文章维护功能的开发,开发过程中使用Area的方法建立了用于维护文章的Controller.View和Model.但是无论代码怎么变对于浏览器来说都是通过一个url地址去 ...
-
C#基础(四)--值类型和引用类型,栈和堆的含义
本文主要是讨论栈和堆的含义,也就是讨论C#的两种类据类型:值类型和引用类型: 虽然我们在.net中的框架类库中,大多是引用类型,但是我们程序员用得最多的还是值类型. 引用类型如:string,Obje ...
-
dns安全 涉及 术语
僵木蠕 以“僵木蠕”(僵尸网络.木马.蠕虫)为代表的网络威胁 僵尸网络是攻击者出于恶意目的,传播僵尸程序bot以控制大量计算机,并通过一对多的命令与控制信道所组成的网络,我们将之称之为僵尸网络,bot ...
-
性能测试工具Locust,一个开源性能测试工具
性能测试工具Locust,一个开源性能测试工具使用Python代码来定义用户行为.用它可以模拟百万计的并发用户访问你的系统.1.它与目前主流的LoadRunner和Jmeter玩法都不一样.2.它完全 ...
-
scRNA-seq单细胞测序数据分析工具汇总
本文总结自一篇综述: Computational approaches for interpreting scRNA-seq data 单细胞分析分为两个层次: cell level gene lev ...