思路:搞懂题意是关键–E满足有共有E天骑车的距离超过E米,求最大的E!

将数组排序,我们假设最大的E是e,e满足条件有e天骑车超过e米,并且e+1不满足有e+1天骑车超过e+1米。那么我们可以逆序统计所有满足的就是答案。


AC代码

#include <stdio.h>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 5;

int a[maxn];

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a, a+n);
    int ans = 1;
    for(int i = n-1; i >= 0 && ans < a[i]; i--) {
        ans++;
    }
    printf("%d\n", ans-1);
    return 0;
}

如有不当之处欢迎指出!

PAT1117. Eddington Number的更多相关文章

  1. A1117. Eddington Number

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

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

  3. PAT 甲级 1117 Eddington Number

    https://pintia.cn/problem-sets/994805342720868352/problems/994805354762715136 British astronomer Edd ...

  4. 1117 Eddington Number (25 分)

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

  5. PAT 1117 Eddington Number [难]

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

  6. 1117. Eddington Number(25)

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

  7. PAT 1117 Eddington Number

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

  8. PAT_A1117#Eddington Number

    Source: PAT A1117 Eddington Number (25 分) Description: British astronomer Eddington liked to ride a ...

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

随机推荐

  1. linux指令--ls

    本篇博客转自http://www.cnblogs.com/peida/archive/2012/10/23/2734829.html,在原作者基础上做了修改和总结. ls命令是linux下最常用的命令 ...

  2. python urllib2与urllib

    1.urllib2可以接受一个Request对象,并以此可以来设置一个URL的headers,但是urllib只接收一个URL. 2.urllib模块可以提供进行urlencode的方法,该方法用于G ...

  3. IE各个版本的差异性

    1.IE6a.不支持png半透明图片,只能用filter实现b.不支持css的max-width.max-height.min-width.min-height其他不用说,一团糟,不过项目中还是得去兼 ...

  4. wget实例

    问题:下载http://web.utah.edu/thorne/computing/网页中所有的文件 命令:wget -c -r -np -k -L -p http://web.utah.edu/th ...

  5. GlusterFS最佳实践

    标签(linux): glusterfs 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 今天我们来从实战中学习glusterfs 环境准备: gluster-s ...

  6. 关系类型字段 -- Django从入门到精通系列教程

    该系列教程系个人原创,并完整发布在个人官网刘江的博客和教程 所有转载本文者,需在顶部显著位置注明原作者及www.liujiangblog.com官网地址. Python及Django学习QQ群:453 ...

  7. DVWA安装问题(phpStudy)

    安装过程出现的问题: 1.PHP function allow_url_include disabled 注意DVWA的版本    PHP version: 5.4.45 打开/phpStudy/ph ...

  8. spring中Bean对象的生命周期

    经过测试对于具体的一个Bean,执行的流程应该是: 1.实例化: 常见的有构造(有参.无参)实例化.静态工厂(方法是静态,通过类名.方法返回获取).实例工厂(专门有个类负责生产对象,需要在bean中配 ...

  9. HTTP/HTTPS GET&POST两种方式的实现方法

    关于GET及POST方式的区别请参照前面文章:http://www.cnblogs.com/hunterCecil/p/5698604.html http://www.cnblogs.com/hunt ...

  10. Python基础篇(二)

    Python最基本的数据结构是序列(sequence),序列中的每个元素被分以以0开头的唯一的一个id号. Python中有6种内建的序列:列表,元组,字符串,Unicode字符串,buffer对象和 ...