<span style="color:#6600cc;">/*
G - 寻找大富翁
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
浙江桐乡乌镇共同拥有n个人,请找出该镇上的前m个大富翁. Input
输入包括多组測试用例.
每一个用例首先包括2个整数n(0<n<=100000)和m(0<m<=10),当中: n为镇上的人数,m为须要找出的大富翁数, 接下来一行输入镇上n个人的財富值.
n和m同一时候为0时表示输入结束. Output
请输出乌镇前m个大富翁的財产数,財产多的排前面,假设大富翁不足m个,则所有输出,每组输出占一行. Sample Input
3 1
2 5 -1
5 3
1 2 3 4 5
0 0 Sample Output
5
5 4 3
By Grant Yuan
2014.7.11
*/
#include<iostream>
#include<stdio.h> #include<stdlib.h>
#include<string.h>
using namespace std;
int n,m;
int a[100003];
int cmp(const void *a,const void *b)
{
return(*(int*)b-*(int*)a);
}
int main()
{int i,j;
while(1){
cin>>n>>m;
if(n==0&&m==0)
break;
for(i=0;i<n;i++)
cin>>a[i];
qsort(a,n,sizeof(a[0]),cmp);
for(j=0;j<m;j++)
if(j==0) cout<<a[j];
else cout<<" "<<a[j];
cout<<endl; }
return 0;
}
</span>

Hdu3785的更多相关文章

  1. HDU3785寻找大富翁~~真真切切的水题

    寻找大富翁 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

随机推荐

  1. BNU OJ 1027 金币系统

    金币系统 Time Limit: 1000ms Memory Limit: 65535KB   64-bit integer IO format: %lld      Java class name: ...

  2. Laya List翻页滚动方案 & List滚动源码解析

    Laya List翻页滚动方案 & List滚动源码解析 @author ixenos 2019-03-29 1.List翻页滚动方案 /** * 计算下一页的起始索引, 不足时补足 * @p ...

  3. cf550D Regular Bridge

    Regular Bridge An undirected graph is called k-regular, if the degrees of all its vertices are equal ...

  4. 手动实现jQuery的toggle()效果

    有时候我们希望实现toggle()切换效果,但是切换的同时需要完成一些其他要做的事情.所以我们需要对jQuery的toggle()函数进行改造. 下面好test2()函数就是一个实现toggle效果的 ...

  5. linux 抓取访问量排行

    需求: 分析图片服务日志,把日志(每个图片访问次数*图片大小的总和)排行,取top10,也就是计算每个url的总访问大小 语句: awk '{a[$1]+=$10;}END{for(i in a){p ...

  6. JVM GC 相关

    http://blog.csdn.net/cutesource/article/details/5904501 http://www.cnblogs.com/dingyingsi/p/3760447. ...

  7. alibaba/fastjson 之 JSONPath

    JOSNPath 是一个非常强大的工具,对于处理 json 对象非常方便. 官方地址:https://github.com/alibaba/fastjson/wiki/JSONPath 基本用法:ht ...

  8. Codeforces 518 D Ilya and Escalator

    Discription Ilya got tired of sports programming, left university and got a job in the subway. He wa ...

  9. 抽球游戏(fwt)

    地址:https://nanti.jisuanke.com/t/26017 分析: 现在是给定p,求是否存在这样的数列c,我们可以让p进行fwt变换,然后把点值都三次方根,然后再把得到的点值ufwt成 ...

  10. Hadoop HDFS 常用命名

    HDFS命令基本格式:hadoop fs -cmd < args > ls 命令hadoop fs -ls / 列出hdfs文件系统根目录下的目录和文件 hadoop fs -ls -R ...