CSU 1867 中南大学网络赛F题 John and Health rate
2017-04-15 21:32
344 查看
题目:
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 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 a single line with the k-th small health rate.
就是输入n,k,然后输入n个数,要求输出从小到大第k个数。
线性时间选择的算法是比较复杂的,这里不需要,因为给出了每个数的范围,所以只需要20001个桶即可。
代码:
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
就是输入n,k,然后输入n个数,要求输出从小到大第k个数。
线性时间选择的算法是比较复杂的,这里不需要,因为给出了每个数的范围,所以只需要20001个桶即可。
代码:
#include<iostream> using namespace std; int num[20001]; int main() { int n, k, h, key; while (cin >> n >> k) { for (int i = 0; i <= 20000; i++)num[i] = 0; for (int i = 0; i < n; i++) { scanf("%d", &h); num[h + 10000]++; } key = 0; while (k>num[key])k -= num[key++]; cout << key - 10000 << endl; } return 0; }
相关文章推荐
- CSU 1867 John and Health rate
- COJ-1867-John and Health rate
- CSU 1866 中南大学网络赛A题 Apache and new sports competition
- CSU 1871 中南大学网络赛E题 简单的数论
- CSU 1869 中南大学网络赛C题 树上最大值
- csu:1914: John and his party
- [CSU 1915 John and his farm]树形DP+LCA
- NodeManager healthy check includes script health checker and local dir checker.
- Radius Sever - Dynamic Vlan and Rate Limit Configuration
- 25 Stats about Conversion Rate Optimization and A/B Testing
- Security and Privacy for Cloud-Based Data Management in the Health Network Service Chain: A Microser
- FPGA 中的警告:Warning: Some pins have incomplete I/O assignments (Missing drive strength and slew rate)
- CSU 1870 中南大学网络赛D题 Legendary
- CSU-ACM2017暑假集训比赛1 B - R2D2 and Droid Army
- android app rate on google play and amazon
- Heart Rate Variability Analysis with the HRV Toolkit: Basic Time and Frequency Domain Measures/背景
- The labor day's schedule and the rate of process
- CSU--------2133: 中南大学2017年ACM暑期集训前期训练题集(基础题)
- Pictures for active reading.Unit 1 Food and health.
- CSU 1312 CX and girls (最短路)