zoukankan      html  css  js  c++  java
  • CSUOJ1867 John and Health rate

    1867: John and Health rate

      Time Limit: 2 Sec     Memory Limit: 128 Mb     Submitted: 328     Solved: 77    


    Description

    The cold and flu season is here.John is worried about his cow. In order to monitor the situation of his cow,he do some inspecting everyday,and record the “health rate” for each cow.The “health rate” is a integer which can show the cow’s health condition.The higher a cow’s health rate is ,the healthier the cow is.What’s more,the doctor told John that the k-th small health rate is dangerous.Because the doctor thought there are at most k healthy cows. So John has to find out which number is the k-th small.Can you help him?

    Input

    Input contains multiple test cases.
    The first line contains two integers n,k (1 ≤ n ≤ 1000000,1<=k<=n) — the number of cows and dangerous number. The second line contains n integers,and the i-th integer ai(-10000<=ai<=10000) is the i-th cow’s health rate

    Output

    Output a single line with the k-th small health rate.

    Sample Input

    2 1
    3 2
    5 2
    -1 0 -2 5 3

    Sample Output

    2
    -1



    其实很简单,就用一个sort就可以解决,时间复杂度为O(nlogn),最小的时间复杂度要用到桶排序?

    #include <iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    
    int n,k,a[1000000];
    
    int main()
    {
        while(~scanf("%d%d",&n,&k)){
            for(int i=0;i<n;i++)
                scanf("%d",&a[i]);
            sort(a,a+n);
             printf("%d
    ",a[k-1]);
        }
        return 0;
    }



  • 相关阅读:
    [算法整理]树上求LCA算法合集
    线段树专题测试2017.1.21
    [数据结构]替罪羊树简介
    图论测试 2017.1.17
    bzoj 2038 A-小Z的袜子[hose]
    洛谷比赛『期末考后的休闲比赛2』
    [题解]bzoj 1861 Book 书架
    bzoj 3223 文艺平衡树
    Splay简介
    python2.7 一个莫名其妙的错误
  • 原文地址:https://www.cnblogs.com/umrx/p/6750162.html
Copyright © 2011-2022 走看看