PAT 1117 Eddington Number

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 <iostream>
#include <algorithm>
using namespace std;
int a[1000000];
int main() {
    int n, e = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    sort(a, a+n, greater<int>());
    while(e < n && a[e] > e+1) e++;
    printf("%d", e);
    return 0;
}

原文地址:https://www.cnblogs.com/A-Little-Nut/p/9502057.html

时间: 2024-10-30 05:02:57

PAT 1117 Eddington Number的相关文章

1117 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. Edding

【PAT甲级】1117 Eddington Number (25分)

题意: 输入一个正整数N(<=100000),接着输入N个非负整数.输出最大的整数E使得有至少E个整数大于E. AAAAAccepted code: 1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 int a[100007]; 5 int num[100007]; 6 map<int,int>mp; 7 int main(){ 8 ios::sync_with_

PAT 1082. Read Number in Chinese (25)

1082. Read Number in Chinese (25) Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output "Fu" first if it is negative. For example, -123456789 is read as "Fu yi Yi er Qian san Bai si

pat 1038 Smallest Number解题心得

题目描述: 1038. Recover the Smallest Number (30) Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can recover many numbers such like 32-321-3214-0229-87 or

PAT 1024. Palindromic Number (25)

1024. Palindromic Number (25) A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Non-palindromic nu

PAT 1082. Read Number in Chinese

#include <cstdio> #include <cstdlib> #include <string> #include <vector> #include <algorithm> using namespace std; const char* d2cn[] = {"ling", "yi", "er", "san", "si", "

PAT 1024 Palindromic Number

#include <cstdio> #include <iostream> #include <cstdlib> #include <algorithm> using namespace std; void print(vector<char> &num) { int len = num.size(); bool value_begin = false; for (int i=0; i<len; i++) { if (!value_

A题目

1 1001 A+B Format(20) 2 1002 A+B for Polynomials(25) 3 1003 Emergency(25) 4 1004 Counting Leaves(30) 5 1005 Spell It Right(20) 6 1006 Sign In and Sign Out(25) 7 1007 Maximum Subsequence Sum(25) 8 1008 Elevator(20) 9 1009 Product of Polynomials(25) 10

转载:oracle null处理

(1)NULL的基础概念,NULL的操作的基本特点NULL是数据库中特有的数据类型,当一条记录的某个列为NULL,则表示这个列的值是未知的.是不确定的.既然是未知的,就有无数种的可能性.因此,NULL并不是一个确定的值.这是NULL的由来.也是NULL的基础,所有和NULL相关的操作的结果都可以从NULL的概念推导出来.判断一个字段是否为NULL,应该用IS NULL或IS NOT NULL,而不能用‘=’.对NULL的判断只能定性,既是不是NULL(IS NULL/IS NOT NULL),而