hdu 1425
题目
#include<stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[1000000];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n,cmp);
for(int i=0;i<m-1;i++)
printf("%d ",a[i]);
printf("%d\n",a[m-1]);
}
return 0;
}
#include<iostream>
using namespace std;
#include<algorithm>
int a[1000000];
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=0; i<n; i++){
scanf("%d",&a[i]);
}
sort(a,a+n);
for(int i=n-1;i>=m;i--)
printf("%d ",a[i]);
printf("%d\n",a[m-1]);
}
【三】:
#include <stdio.h>
int a[1000000];
int main(){
int n,m,t;
while(~scanf("%d%d",&n,&m))
{
for(int i=0;i<n;i++){
scanf("%d",&t);
a[500000+t]=1;
}
for(int i=1000001;m>0;i--)
{
if(a[i])
{
printf("%d",i-500000);
if(m>1) printf(" ");
else
printf("\n");
m--;
}
}
}
return 0;
}
hdu 1425的更多相关文章
- hdu 1425 Happy 2004
题目链接 hdu 1425 Happy 2004 题解 题目大意: 求 \[\sum_{d|2004^{x}}d\ mod\ 29\] 记为\(s(2004^x)\) \(sum(2004^{x})= ...
- hdu 1425 sort 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1425 常规的方法是对输入的数从大到小进行排序(可以用sort或qsort),然后输出前m大的数. 不过 ...
- E题hdu 1425 sort
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1425 sort Time Limit: 6000/1000 MS (Java/Others) M ...
- HDU 1425 sort hash+加速输入
http://acm.hdu.edu.cn/showproblem.php?pid=1425 题目大意: 给你n个整数,请按从大到小的顺序输出其中前m大的数. 其中n和m都是位于[-500000,50 ...
- hdu 1425:sort(排序,经典题。快排模板)
sort Time Limit : 6000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submissi ...
- HDU 1425 sort(堆排序/快排/最大堆/最小堆)
传送门 Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不 ...
- HDU 1425 sort 【哈希入门】
题意:给出n个数,输出前m大的数 和上一题一样,将输入的数加上一个极大地值作为地址 #include<iostream> #include<cstdio> #include&l ...
- HDU 1425 sort 题解
选择出数列中前k个最大的数. 这里由于数据特殊.所以能够使用hash表的方法: #include <cstdio> #include <algorithm> #include ...
- hdu 1425 sort
Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行 ...
- HDU 1425 C++使用sort函数
sort Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...
随机推荐
- CSS3 弹性盒模型 box-flex
说明:本文档兼容性测试基础环境为:windows系统:IE6-IE10, Firefox6.0, Chrome13.0, Safari5.1, Opera11.51 语法: box-flex:< ...
- mysql备份的三种方式
一.备份的目的 做灾难恢复:对损坏的数据进行恢复和还原需求改变:因需求改变而需要把数据还原到改变以前测试:测试新功能是否可用 二.备份需要考虑的问题 可以容忍丢失多长时间的数据:恢复数据要在多长时间内 ...
- 安装和使用iOS的包管理工具CocoaPods
CocoaPods是ruby实现的,需要用ruby进行安装,mac自带ruby,如果没有ruby的需要先安装ruby. 安装CocoaPods命令 安装CocoaPods命令:sudo gem i ...
- 139. Word Break (String; DP)
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- ios 点击Home问题
应用可以在后台运行或者挂起,该场景的状态跃迁过程见图2-22,共经历3个阶段4个状态:Active → Inactive → Background→Suspended. q 在Active→Ina ...
- css学习-css引入&css选择
一.引入css的方式,一共有4种,我们只需要掌握三种就可以了,@import的方法我们不做掌握 1.第一种引入的方法 <!--1.第一种引入css的方法--> <h1 style=& ...
- SweetAlert2 弹窗
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- dede添加自定义函数
在dede安装目录下的include/extend.func.php添加自定义函数: /** * 获取文章第一张图片 */ function getFirstImg($arcId) { global ...
- 移动端bug之解决方式
1.Android中元素被点击时产生的边框: * { -webkit-tap-highlight-color: rgba(250,250,250,0); /*更改点击事件的焦点色*/} 2.去除移 ...
- Linux objdump命令
一.简介 objdump命令是用查看目标文件或者可执行的目标文件的构成的gcc工具. 二.选项 http://my.oschina.net/alphajay/blog/7729 http://man. ...