sort
Time Limit : 6000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 82 Accepted Submission(s) : 22Font: Times New Roman | Verdana | GeorgiaFont Size: ← →Problem Description
给你n个整数,请按从大到小的顺序输出其中前m大的数。
Input
每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-500000,500000]的整数。
Output
对每组测试数据按从大到小的顺序输出前m大的数。
Sample Input
5 33 -35 92 213 -644
Sample Output
213 92 3
Hint
Hint
请用VC/VC++提交 Author
LL
Source
ACM暑期集训队练习赛(三)
代码:
#include<stdio.h>
int a[1000001]; int main() { int m,n,i,t; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0;i<1000001;i++) a[i]=0; while(n) { scanf("%d",&t); a[500000+t]=1; n--; } for(n=1000000;n>=0;n--) if(a[n]) { if(!m--)break; printf("%d%c",n-500000,m>=1?' ':'\n'); } }
return 0;
} |
1425 sort(特别的排序方法)
最新推荐文章于 2021-09-05 00:10:24 发布