COJ-1867-John and Health rate
来源:互联网 发布:nat123端口映 编辑:程序博客网 时间:2024/05/17 08:45
1867: John and Health rate
Submit Page Summary Time Limit: 2 Sec Memory Limit: 128 Mb Submitted: 367 Solved: 85
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
Hint
Source
中南大学第十一届大学生程序设计竞赛网络预选赛
题目大意:求序列中的第k小数。
解题思路:利用快排的划分思想,减治思想。
#include<iostream>#include<cstring>#include<cmath>#include<ctime>#include<cstdlib>#include<algorithm>#include<iomanip>#include<fstream>#include<map>using namespace std;const int MAXN=1e6+5;int a[MAXN];int Partition(int L,int R){ int i,j,x,tmp; i=L; j=R+1; x=a[L]; while(true) { while(a[++i]<x); while(a[--j]>x); if(i>=j) break; tmp=a[i]; a[i]=a[j]; a[j]=tmp; } a[L]=a[j]; a[j]=x; return j;}int RandomPar(int L,int R){ int i=L+rand()%(R-L+1); int tmp=a[i]; a[i]=a[L]; a[L]=tmp; return Partition(L,R);}int Find(int L,int R,int k){ int i,j; if(L==R) return a[L]; i=RandomPar(L,R); //i=Partition(L,R); j=i-L+1; if(k==j) return a[i]; if(k<j) return Find(L,i-1,k); else return Find(i+1,R,k-j);}int main(){ int n,k; while(scanf("%d%d",&n,&k)!=EOF) { for(int i=1;i<=n;i++) { scanf("%d",&a[i]); }// for(int i=1;i<=n;i++)// {// cout<<a[i]<<" ";// }// cout<<endl; printf("%d\n",Find(1,n,k)); }}
- COJ-1867-John and Health rate
- CSU 1867 John and Health rate
- CSU 1867 中南大学网络赛F题 John and Health rate
- Science and Your Health
- precision and recall rate
- precision and recall rate
- Hit rate and False alarm rate
- COJ-1004-Xi and Bo
- 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
- health
- bootstrapTable 插件使用注意点
- A
- 欢迎使用CSDN-markdown编辑器
- 二叉树
- HADDOP安装配置过程(新手初学)
- COJ-1867-John and Health rate
- webpack-dev-server的使用
- 王爽《汇编语言》课程设计二续(包含软盘操作)
- springboot 使用校验框架validation校验
- Linux下编译pjproject-2.6并运行例程simple_pjsua
- Json初步知识
- codevs 1222 信与信封问题(二分图匹配 可确定的关系)
- 虚拟机搭建CDH-第四讲-安装第一台虚拟机需要修改的
- 日夜间切换