PAT甲级1117
来源:互联网 发布:mac mysql 配置文件 编辑:程序博客网 时间:2024/05/04 16:33
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. 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:106 7 6 9 3 10 8 2 7 8Sample Output:
6
#include <cstdio>#include <algorithm>using namespace std;int a[1000000];bool cmp1(int a, int b) {return a > b;}int main() {int n;scanf("%d", &n);for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);}sort(a + 1, a + n + 1, cmp1);//从大到小排序int ans = 0;int p = 1;while (ans <= n && a[p] > p) {//若满足,那么1~p-1对应的数肯定是大于p的,然后如果a[p]>p那么刚好就满足那个爱丁顿数ans++;p++;}printf("%d", ans);return 0;}
- PAT甲级1117
- PAT 甲级
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- PAT(甲级)1010
- PAT(甲级)1011
- PAT(甲级)1012
- PAT(甲级)1013
- PAT(甲级)1014
- PAT(甲级)1015
- PAT(甲级)1016
- 双色点阵心形显示
- 总结:三种方式实现单击页签切换页面效果
- JavaScript中的cookies
- 「Unity2D」使用Unity创建一个2D游戏系列-2
- 判断字符串是否为回文,初学者,请多指教
- PAT甲级1117
- 通過分區(Partition)提升MySQL性能
- RF-可变参数关键字使用
- 枚举的使用
- python自动化之路-html补充
- 第二道ctf题解
- [Haskell on HackerEarth] Find Product
- surf特征原理
- MySQL 設定檔優化-cache