其他分享
首页 > 其他分享> > PAT (Advanced Level) Practice 1117 Eddington Number (25 分) 凌宸1642

PAT (Advanced Level) Practice 1117 Eddington Number (25 分) 凌宸1642

作者:互联网

PAT (Advanced Level) Practice 1117 Eddington Number (25 分) 凌宸1642

题目描述:

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

译:英国科学家爱丁顿喜欢骑行。据说为了展示他的技巧,他定义了一个"爱丁顿数",E —— 满足 E 天 骑行多余 E 公里 的最大的整数。爱丁顿自己的 E 是 87。现在给定 N 个每天的骑行距离,你应该找出相应的 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.

译:每个输入文件包含一个测试用例。 对于每个用例,第一行给定一个正整数 N (≤105),表示贡献骑行的天数。接下来一行给定 N 个非负整数,表示每天的骑行距离。


output Specification (输出说明):

For each case, print in a line the Eddington number for these N days.

译:对于每个测试用例,在一行中输出这 N 天的爱丁顿数。


Sample Input (样例输入):

10
6 7 6 9 3 10 8 2 7 8

Sample Output (样例输出):

6

The Idea:

The Codes:

#include<bits/stdc++.h>
using namespace std ;
vector<int> num ;
int n ; 
bool cmp(int a, int b){
	return a > b ;
}
int main(){
	scanf("%d" , &n) ;
	num.resize(n + 1) ;
	for(int i = 1 ; i <= n ; i ++) scanf("%d" , &num[i]) ;
	sort(num.begin() + 1 , num.end() + 1, cmp) ; // 从大到小排序
	for(int i = 1 ; i <= num.size() ; i ++){
		if(num[i] <= i){
			cout << i - 1 << endl ;
			break; 
		}
	}
	return 0 ;
}

标签:25,PAT,1642,int,爱丁顿,days,line,骑行,Eddington
来源: https://www.cnblogs.com/lingchen1642/p/15187645.html