CSU 1867 John and Health rate
来源:互联网 发布:周立功单片机同类公司 编辑:程序博客网 时间:2024/05/17 08:43
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 13 25 2-1 0 -2 5 3
Sample Output
2-1
Hint
给一串数字,求第K大的,水题,粗暴的方式是用STL的sort函数,然后直接输出第K个。
但这个题用桶排序做更优,一个数字一个坑,然后从左到右扫一遍就行了。
#include <cstdio>#include <cstring>#define MAXN 10000int n,k;int numberBucket[MAXN*2+5];int main(){ while(scanf("%d%d",&n,&k)>0){ memset(numberBucket,0, sizeof(numberBucket)); while(n--){ int tempNum; scanf("%d",&tempNum); numberBucket[tempNum+MAXN]++; } for(int i=0;i<MAXN*2+5;i++) { k-=numberBucket[i]; if(k<=0){ printf("%d\n",i-MAXN); break; } } } return 0;}
- CSU 1867 John and Health rate
- COJ-1867-John and Health rate
- CSU 1867 中南大学网络赛F题 John and Health rate
- csu:1914: John and his party
- [CSU 1915 John and his farm]树形DP+LCA
- Science and Your Health
- precision and recall rate
- precision and recall rate
- Hit rate and False alarm rate
- Rate Control and H.264
- Rate Control and H.264
- webrtc frame rate and size;
- weight decay and learning rate
- Momentum and Learning Rate Adaptation
- Fill-rate, Canvases and input
- Health
- Health
- Health
- 第六章 PX4-Pixhawk-Sensors解析
- C++基础之智能指针
- 1079. Total Sales of Supply Chain (25)
- (逆向)angr 执行二进制函数
- 51nod 1101 换零钱
- CSU 1867 John and Health rate
- hibernate中联合主键的使用
- 选择语句 while 和do..while
- gcc-stack-protector机制
- Android屏幕适配方案http://blog.csdn.net/lmj623565791/article/details/45460089
- React入门学习
- 国际专利分类表(2016版)
- uva572 -- Oil Deposits
- java_集合