PAT 甲级 1117 Eddington Number
https://pintia.cn/problem-sets/994805342720868352/problems/994805354762715136
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 <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
long long a[maxn]; int main() {
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
scanf("%lld", &a[i]);
sort(a + 1, a + 1 + n); for(int i = n; i >= 1; i --) {
int L = 1, R = n, pos = -1;
while(L <= R) {
int mid = (L + R) / 2;
if(a[mid] > 1LL * i) R = mid - 1, pos = mid;
else L = mid + 1;
} if(pos == -1) continue;
if(n - pos + 1 >= i) {
printf("%d\n", i);
return 0;
}
}
printf("0\n"); return 0;
}
午睡结束 最近也太爱睡觉了吧
PAT 甲级 1117 Eddington Number的更多相关文章
- 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 ...
- 1117 Eddington Number (25 分)
1117 Eddington Number (25 分) British astronomer Eddington liked to ride a bike. It is said that in o ...
- PAT 1117 Eddington Number
British astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, h ...
- 1117. 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 (25分)
题意: 输入一个正整数N(<=100000),接着输入N个非负整数.输出最大的整数E使得有至少E个整数大于E. AAAAAccepted code: #define HAVE_STRUCT_TI ...
- PAT甲题题解-1117. Eddington Number(25)-(大么个大水题~)
如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...
- PAT 甲级 1024 Palindromic Number
1024. Palindromic Number (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...
- PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)
1024 Palindromic Number (25 分) A number that will be the same when it is written forwards or backw ...
随机推荐
- Maven配置本地库加载ojdbc14-10.2.0.4.0.jar文件
因为ojdbc14-10.2.0.4.0.jar是要收费的,所以Maven的远程库里没有这个资源,只能通过配置本地库来加载到J2EE工程里,做法如下: 第一步:在网上下载ojdbc14.jar,然 ...
- Publisher和Subscriber节点
一.Publisher节点 /*"ros/ros.h"里面包含了ROS系统内最常用的一些头文件,包含此文件,便可以使用ROS的核心功能.*/#include "ros/r ...
- PAT B1050 螺旋矩阵 (25 分)
本题要求将给定的 N 个正整数按非递增的顺序,填入“螺旋矩阵”.所谓“螺旋矩阵”,是指从左上角第 1 个格子开始,按顺时针螺旋方向填充.要求矩阵的规模为 m 行 n 列,满足条件:m×n 等于 N:m ...
- PAT B1035 插入与归并 (25 分)
根据维基百科的定义: 插入排序是迭代算法,逐一获得输入数据,逐步产生有序的输出序列.每步迭代中,算法从输入序列中取出一元素,将之插入有序序列中正确的位置.如此迭代直到全部元素有序. 归并排序进行如下迭 ...
- 3-51单片机ESP8266学习-AT指令(学会刷固件)
前言:体验一下刷固件(给单片机更新程序) 上一篇链接 http://www.cnblogs.com/yangfengwu/p/8757036.html 源码链接:https://pan.baidu. ...
- TTL,COMS,USB,232,422,485电平之详细介绍及使用
如有错误敬请指导! 今天来详细介绍一下TTL,COMS,USB,232,422,485电平,以及之间的转换问题. 有些地方的引脚图可能不是规范的,具体引脚以自己的模块资料为主,这篇文章着重介绍使用.. ...
- lwip lwiperf 方法进行性能测试 4.5MB/S
硬件配置: STM32F407 + DP83848 + FreeRTOS V10.1.1 + LWIP 2.1.2 2018年12月5日14:31:24 1.先读取 PHY 寄存器 , 查看 自 ...
- C51中的关键字和ANSIC标准关键字
C51中的关键字和ANSIC标准关键字 作 者:武力戡乱 修改日期:2017-09-05 备 注: 1.总备注信息 2.联系方式 3.其它博文链接:武力戡乱博客目录总表 内 ...
- CentOS 建立本地yum源服务器
安装CentOS系统,配置系统的网络环境 配置静态IP vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet O ...
- # 2017-2018-2 20155319『网络对抗技术』Exp7:网络欺诈防范
2017-2018-2 20155319『网络对抗技术』Exp7:网络欺诈防范 一.原理与实践说明 1.实践目标 本实践的目标是:理解常用网络欺诈背后的原理,以提高防范意识,并提出具体防范方法. 2. ...