PAT A1117 Eddington Number (25 分)——数学题
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的数要特殊处理
最新文章
- js-JavaScript高级程序设计学习笔记19
- Swift - 界面的跳转模式
- Pyqt 动态的添加控件
- Hadoop生态圈
- 2016huasacm暑假集训训练三 F - Jungle Roads
- 通过Ajax实现增删改查
- Velocity魔法堂系列三:模板与宿主环境通信
- [Java Basics] Stack, Heap, Constructor, I/O, Immutable, ClassLoader
- css 动画类库Animate.css
- TYVJ P1016 装箱问题
- mysql-5.6.15_winX64在win764位系统下的安装操作步骤总结
- .Net下一个Winform方案可以让MessageBox.Show它显示在父窗口的中间
- [译]Java 设计模式之外观
- 微信小程序心得
- C#文件流的读写
- django 生产环境部署建议
- ASP.NET Core如何设置请求超时时间
- system.Data.Entity.Infrastructure.DbUpdateConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0) 问题
- Linux 完整卸载oracle和grid软件
- APP主要测试类型及测试点总结
热门文章
- CSS属性之position讲解
- Linux&#160;学习笔记之超详细基础linux命令&#160;Part&#160;4
- Django ModelForm 校验数据格式
- springcloud 入门 7 (zuul路由网关)
- Spring Boot 技术总结
- 将爬取的数据保存到mysql中
- [MapReduce_add_1] Windows 下开发 MapReduce 程序部署到集群
- pip更新及Requirement already up-to-date解决方法
- 【PAT】B1051 复数乘法(15 分)
- CSRF 漏洞原理详解及防御方法