• PAT 1060 爱丁顿数(25)(STL-multiset+思路)


    1060 爱丁顿数(25 分)

    英国天文学家爱丁顿很喜欢骑车。据说他为了炫耀自己的骑车功力,还定义了一个“爱丁顿数” E ,即满足有 E 天骑车超过 E 英里的最大整数 E。据说爱丁顿自己的 E 等于87。

    现给定某人 N 天的骑车距离,请你算出对应的爱丁顿数 E(≤N)。

    输入格式:

    输入第一行给出一个正整数 N (≤10​5​​),即连续骑车的天数;第二行给出 N 个非负整数,代表每天的骑车距离。

    输出格式:

    在一行中给出 N 天的爱丁顿数。

    输入样例:

    10
    6 7 6 9 3 10 8 2 7 8
    

    输出样例:

    6

    PS

        我的思路:将得到的天数输入进multiset容器中降序排列,只需比较天数与汽车距离(骑车距离>天数:说明是一个爱丁顿数),然后输出最大E即可。

       注意:1、当出现非爱丁顿数时,并不意味着后面的数不是爱丁顿数。

                  2、尽量降低时间复杂度。(测试点3)

    #include<iostream>
    #include<set>
    using namespace std;
    int main() {
    	multiset<int, greater<int>> s;   //降序排列
    	int n, t;
    	cin >> n;
    	for (int i = 0; i < n; i++) {
    		cin >> t;
    		s.insert(t);
    	}
    	int max = 0,count = 1;    //记录天数
    	for (auto it = s.begin(); it != s.end(); count++, it++) {
    		if (*it > count)
    			max = count > max ? count : max;  //找最大E
    	}
    	cout << max;
    	return 0;
    }
    
  • 相关阅读:
    Xamarin.FormsShell基础教程(3)Shell项目构成
    Xamarin.FormsShell基础教程(2)创建Shell解决方案
    Xamarin.Forms Shell基础教程(1)
    点击按钮,返回顶部
    三角形(css3)
    改变字体大小的媒体查询代码封装
    将毫秒格式化为分钟和秒 ,并补0
    节流函数
    打乱数组方法
    css使用总结
  • 原文地址:https://www.cnblogs.com/F-itachi/p/9974409.html
Copyright © 2020-2023  润新知