Second Order Statistics (CF22A) 题解

这是一道CF的题目(Code Forces 22A)

题目(英文):

Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.

输入格式:

The first input line contains integer nn ( 1<=n<=1001<=n<=100 ) — amount of numbers in the sequence. The second line contains nn space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.

输出格式:

If the given sequence has the second order statistics, output this order statistics, otherwise output NO.

题意翻译(中文)
给定一个数组,输出其中第二小的整数(相等的整数只计算一次)
输入:
第一行,一个整数n(1<=n<=100),表示数组长度
第二行,n个绝对值小于100的整数。
输出:
一行。如果该数组存在第二小整数,则输出。如果不存在,则输出NO.

题目不难理解

主要的是排序。(Sort快排一遍加个特判不就好了吗?)

过滤第一小的数,用剩下的数排一次。

任何一个伟大的思想,都有一个微不足道的开始。

< 如果Sort不会,下有参考文献 >

放代码:

#include<bits/stdc++.h>
using namespace std;
int n,a[107],l;
int main(){scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&a[i]);sort(a+1,a+n+1);l=a[1];for(int i=1;i<=n;i++){if(a[i]!=l){printf("%d\n",a[i]);return 0;}}printf("NO\n");return 0;
}

  

参考文献:

  Sort百度百科

排序算法总结

OVER!


写于2019年1月2日
作者:WSJ

转载于:https://www.cnblogs.com/wangshengjun/p/cf22A.html

CF22A Second Order Statistics相关推荐

  1. 算法成长之路------CF22A Second Order Statistics

    学习目标:算法学习-Day16 题库: 洛谷题库 每天保持发布一篇Java或C算法题解! 题目: 给定一个数组,输出其中第二小的整数(相等的整数只计算一次). 输入格式: 第一行,一个整数 n(1≤n ...

  2. CF993E Nikita and Order Statistics

    CF993E Nikita and Order Statistics 题意: 给你一个数组 a1∼na_{1 \sim n}a1∼n​,对于 k=0∼nk = 0 \sim nk=0∼n,求出有多少个 ...

  3. Lecture 6 Order Statistics

    Given n elements in array, find kth smallest element (element of rank k) Worst-case linear time orde ...

  4. order statistics(找最ith小数值)问题

    order statistics就是在一堆无序的序列中查找第n小元素. 分为2种: 1.静态,也就是序列给定,并且不再变化,此时采取类似快排的做法,需要改变判断条件和结束条件. 2动态,就是元素在不断 ...

  5. CodeForces - 993E Nikita and Order Statistics

    (暂时没有vjudge题面,CF的题面又太丑2333,直接口述了) 题目大意:给你一个长度为n的序列a[],和一个数x,对于每个i= 0~n ,求有多少个子区间满足恰好有i个数<x. sol: ...

  6. CF993E:Nikita and Order Statistics(FFT)

    Description 给你一个数组 $a_{1 \sim n}$,对于 $k = 0 \sim n$,求出有多少个数组上的区间满足:区间内恰好有 $k$ 个数比 $x$ 小.$x$ 为一个给定的数. ...

  7. A. Second Order Statistics(sort 水题)

    AC代码如下: #include<iostream> #include<algorithm> #include<string> using namespace st ...

  8. CodeForces - 22A Second Order Statistics【水题】

    题目链接:https://codeforces.com/contest/22/problem/A #include <iostream> #include <vector> # ...

  9. Stream Processing:滑动窗口的聚集(aggregation)操作的优化算法讲解

    本文将要讲解流处理中滑动窗口聚集操作的相关优化算法.将分别从下面几个方面讲解: 什么是滑动窗口? 什么是滑动窗口的聚集操作? 聚集操作的优化的必要性在哪里? 有哪些优化算法,它们的原理分别是什么? 4 ...

最新文章

  1. (11)Xamarin.iOS - 新增iPhone storyboard
  2. 手动修改user-agent
  3. antd form 初始化时间
  4. 替换WordPress调用的Google前端库为360镜像的库
  5. Qt:Windows编程—DLL注入与卸载
  6. 大限将至?Google先知
  7. JS讲解跟遇到的问题
  8. 编译原理的first、follow、select
  9. Codeforces Round #260 (Div. 1) A - Boredom DP
  10. 电脑虎牙,虎牙助手主播版电脑版
  11. python3随机种子的使用及理解
  12. Java对象转Map的解决办法_java对象转map怎么操作?map如何转化成Java对象?
  13. 第四周作业上(2014.3.31)
  14. Spark性能优化之-数据倾斜
  15. MongoDB 文档的高级查询操作
  16. 信息系统安全等级保护相关法规及重要国家标准汇总目录
  17. android音乐播放器实现,Android实现简单音乐播放器(MediaPlayer)
  18. 一个基于Python的体重BMI计算程序
  19. Python在操作系统层面上的操作
  20. 时间倒数计时器_如何建立倒数计时器

热门文章

  1. MSXML2.ServerXMLHTTP
  2. 调戏chatGPT(二)下围棋
  3. 数据分析之股票市场价格分析
  4. [译] Chrome 73 开发者工具新特性
  5. centos7 php安装流程
  6. Policy-Based Method RL
  7. asp.net 隐藏url 简便方法
  8. realmeq2可以刷鸿蒙系统吗,realmeQ2Pro有NFC功能吗?可以用realmeQ2Pro刷公交和地铁吗...
  9. Android 让注册商标R往上移
  10. 信用百度公司商标信息爬取