【水题】HDU--1280 前m大的数
还记得Gardon给小希布置的那个作业么?(上次比赛的1005)其实小希已经找回了原来的那张数表,现在她想确认一下她的答案是否正确,但是整个的答案是很庞大的表,小希只想让你把答案中最大的M个数告诉她就可以了。
给定一个包含N(N<=3000)个正整数的序列,每个数不超过5000,对它们两两相加得到的N*(N-1)/2个和,求出其中前M大的数(M<=1000)并按从大到小的顺序排列。
Input
输入可能包含多组数据,其中每组数据包括两行:
第一行两个数N和M,
第二行N个数,表示该序列。
Output
对于输入的每组数据,输出M个数,表示结果。输出应当按照从大到小的顺序排列。
Sample Input
4 4
1 2 3 4
4 5
5 3 6 4 Sample Output
7 6 5 5
11 10 9 9 8
题解:
sort的简单应用。
AC代码:
#include<stdio.h>
#include<algorithm>
using namespace std;
bool cmp(int x,int y)
{
return x>y;
}
int b[];
int main()
{
int n,m,a[],i,j,k;
while(scanf("%d %d",&n,&m)!=EOF)
{k=;
for(i=;i<n;i++)
scanf("%d",&a[i]);
for(i=;i<n-;i++)
for(j=i+;j<n;j++)
b[k++]=a[i]+a[j];
sort(b,b+k,cmp);
for(i=;i<m;i++)
printf("%d%c",b[i],i<m-?' ':'\n'); } return ;
}
【水题】HDU--1280 前m大的数的更多相关文章
- HDU 1280 前m大的数
http://acm.hdu.edu.cn/showproblem.php?pid=1280 前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- HDU 1280 前m大的数【排序 / hash】
前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu 1280 前m大的数 哈希
前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- HDU 1280 前m大的数(排序,字符串)
前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- <hdu - 1280> 前M大的数 (注意其中的细节)
这是杭电hdu上的链接http://acm.hdu.edu.cn/showproblem.php?pid=1280 Problem Description: 还记得Gardon给小希布置的那个作业么 ...
- HDU 1280 前m大的数 基数排序
http://acm.hdu.edu.cn/showproblem.php?pid=1280 题目大意: 给你N(N<=3000)个数(这些数不超过5000),要求输出他们两两相加后和最大的M( ...
- HDU 1280 前m大的数【哈希入门】
题意:中文的题目= =将各种组合可能得到的和作为下标,然后因为不同组合得到的和可能是一样的, 所以再用一个数组num[]数组,就可以将相同的和都记录下来 #include<iostream> ...
- hdu 1280 前m大的数(排序)
题意:排序 思路:排序 #include<iostream> #include<stdio.h> #include<algorithm> using namespa ...
- 杭电 1280 前m大的数
http://acm.hdu.edu.cn/showproblem.php?pid=1280 前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memor ...
随机推荐
- 如何卸载CentOS自带的apache
查看安装的组件: rpm -qa | grep httpd 如果预装有apache,那么会显示像httpd-2.2.3-22.el5.centos这种的组件名. 卸载组件: rpm -e httpd- ...
- thinkphp中try catch的运用
public function doedit_set(){ $info=$this->_post("info"); $id=$this->_post("id& ...
- 安装wamp的方法及过程
地址栏输入:http://www.xiazaiba.com/html/27954.html下载wamp2.5版本,根据过程安装,其中会安装一些垃圾软件把不该勾选的去掉就可以.点击next,下一步下一步 ...
- 函数的上下文就是函数里面的this是谁
规律1:函数用圆括号调用,函数的上下文是window对象 比如小题目: function fun(){ var a = 888; alert(this.a); //实际上访问的是window.a } ...
- Oracle DECODE函数的用法详解
Oracle DECODE函数使用方法: 1.比较大小select decode(sign(变量1-变量2),-1,变量1,变量2) from dual; --取较小值sign()函数根据某个值是0. ...
- MySQL自动化(全量+增量)备份脚本
文章转自:http://www.it-hack.cn/forum.php?mod=viewthread&tid=220&extra=page%3D1 一.MySQL的日常备份方案: 全 ...
- Linux常见命令语句
查看当前目录: pwd 查看文件具体大小: ls -l 返回上一级: cd.. 返回根目录: cd / 创建一个隐藏文件 vim .test 显示隐藏文件:ls -a 编辑文件: 1.vim 文件名 ...
- DotNetCore跨平台~问题~NETCoreAPP, Version=v1.0' compatible with one of the target runtimes: 'win10-x64
回到目录 新建console项目之后,编译程序出现以下错误: Can not find runtime target for framework '.NETCoreAPP, Version=v1.0' ...
- Python如何实现单步调试
遇到大型python项目,如何定位问题和监控程序的运行状态是一个程序员必须掌握的技能,今天小编为你带来python程序的单步调试方法,方便易用,简单易记! 首先你需要在所调试程序的开头中:import ...
- forEach( ) map( ) for( in ) for ( of )
====forEach()和map()遍历 共同点: 1.都是循环遍历数组中的每一项. 2.forEach() 和 map() 里面每一次执行匿名函数都支持3个参数:数组中的当前项item,当前项的索 ...