PAT 甲级 1117 Eddington Number

时间:2022-01-16 21:42:44

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 (≤10​5​​), 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的更多相关文章

  1. 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 ...

  2. PAT 1117 Eddington Number &lbrack;难&rsqb;

    1117 Eddington Number (25 分) British astronomer Eddington liked to ride a bike. It is said that in o ...

  3. 1117 Eddington Number (25 分)

    1117 Eddington Number (25 分) British astronomer Eddington liked to ride a bike. It is said that in o ...

  4. PAT 1117 Eddington Number

    British astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, h ...

  5. 1117&period; Eddington Number&lpar;25&rpar;

    British astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, h ...

  6. 【PAT甲级】1117 Eddington Number &lpar;25分&rpar;

    题意: 输入一个正整数N(<=100000),接着输入N个非负整数.输出最大的整数E使得有至少E个整数大于E. AAAAAccepted code: #define HAVE_STRUCT_TI ...

  7. PAT甲题题解-1117&period; Eddington Number&lpar;25&rpar;-(大么个大水题~)

    如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...

  8. PAT 甲级 1024 Palindromic Number

    1024. Palindromic Number (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

  9. PAT 甲级 1024 Palindromic Number &lpar;25 分&rpar;(大数加法,考虑这个数一开始是不是回文串)

    1024 Palindromic Number (25 分)   A number that will be the same when it is written forwards or backw ...

随机推荐

  1. Visual Studio Code 配置指南

    Visual Studio Code (简称 VS Code)是由微软研发的一款免费.开源的跨平台文本(代码)编辑器.在我看来它是「一款完美的编辑器」. 本文是有关 VS Code 的特性介绍与配置指 ...

  2. POJ 1979 Red and Black【DFS】

    标准DFS,统计遍历过程中遇到的黑点个数 #include<cstdio> #include<vector> #include<queue> #include&lt ...

  3. rabbitmq集群安装

        在配置文件中配置集群没有成功,但是使用命令行成功了,以下是过程请参考.     场景:两台机器,一台是10.1.3.95 hostname为mq1,一台是10.1.3.96 hostname为 ...

  4. codeforces——Little Pony and Sort by Shift

    /* 题目大意:给你一个序列,不断地将最后边的数值移动到最前边,问最少经过多少次可以变成一个单调递增的序列! 如果不能则输出-1. 如果该序列按照不断从后向前移动排序成功,那么该序列要么只有一个单调递 ...

  5. php访问全局变量

    函数之外声明的变量拥有 Global 作用域,只能在函数以外进行访问. 函数内部声明的变量拥有 LOCAL 作用域,只能在函数内部进行访问. PHP 同时在名为 $GLOBALS[index] 的数组 ...

  6. idea使用maven启动tomcat

    1.设置tomcat,如图: 2.添加war包 3.修改pom.xml 删除可能的选项,如果有下面的代码,删除掉 4.选择使用的resources目录 5.启动即可

  7. (转)js一道比较考验的题目

    转载下别人曾经出过的一道面试题,此题是他出的一套前端面试题中的最后一题,用来考核面试者的JavaScript的综合能力,很可惜到目前为止的将近两年中,几乎没有人能够完全答对,并非多难只是因为大多面试者 ...

  8. 查看windows系统热键占用情况

    有时候我们经常用一些软件中的快捷键,但是会发现快捷键设置的很正确,但是就是不起作用.这就是因为这些快捷键被系统或者其他软件占用了. 那么这时我们怎么知道是哪个软件占用了呢?这确实是个纠结的问题,还好大 ...

  9. apache开源项目-- UIMA

    UIMA (Unstructured Information Management applications) 是一个软件系统,用来分析大量的非结构化信息从而发掘中对最终用户有用的知识点,一个最典型的 ...

  10. KDE子项目一览 good

    https://www.kde.org/applications/development/ https://www.kde.org/applications/graphics/ https://www ...