题目11:Sort
来源:互联网 发布:网络测速器在线测网速 编辑:程序博客网 时间:2024/05/19 12:12
http://ac.jobdu.com/problem.php?cid=1040&pid=10
- 题目描述:
给你n个整数,请按从大到小的顺序输出其中前m大的数。
- 输入:
每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且都处于区间[-500000,500000]的整数。
- 输出:
对每组测试数据按从大到小的顺序输出前m大的数。
- 样例输入:
5 33 -35 92 213 -644
- 样例输出:
213 92 3
// 题目11:Sort.cpp: 主项目文件。#include "stdafx.h"#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <string>#include <set>#include <map>#include <queue>#include <stack>using namespace std;const int N=1000003;bool hashTable[N];#define more 500000int main(){ //freopen("F:\\test.txt","r",stdin); //freopen("F:\\output.txt","w",stdout);int n,m;while(scanf("%d%d",&n,&m)!=EOF){memset(hashTable,0,sizeof(hashTable));for(int i=0;i<n;i++){int tmp;cin>>tmp;hashTable[more+tmp]=true;}int cnt=0;bool flag=true;for(int i=N-1;i>=0;i--){if(hashTable[i]){cnt++;if(flag){flag=false;printf("%d",i-more);}elseprintf(" %d",i-more);}if(cnt==m)break;}printf("\n");} return 0;}
- 题目1431:Sort 题目11
- 题目11:Sort
- 11-题目1431:Sort
- 题目1431:Sort
- 题目1431:Sort
- 题目1431:Sort
- 题目1431:Sort
- 题目1431:Sort
- leetcode做题总结,题目Sort List 2013/11/16
- 九度题目1431:Sort
- 九度 题目1431:Sort
- LeetCode题目4:Sort List
- LeetCode之Sort题目汇总
- 九度题目1431:Sort
- 【九度】题目1431:Sort
- LeetCode算法题目:Sort List
- LeetCode算法题目:Sort Colors
- leetcode做题总结,题目Insertion Sort List 2013/11/12
- 需求 接口变更
- ASP.NET里session和cookie的区别是什么?
- 题目15:叠筐
- PHP运算符及php取整函数
- 题目13:剩下的树
- 题目11:Sort
- OpenStack的架构详解(6)
- Lab1:初见树莓派(Raspberry)(windows平台)
- discuz安装提示ucenter url有误
- I2C设备驱动编写,struct i2c_device_id,struct i2c_driver,i2c_add_driver,i2c_register_board_info
- OpenStack的架构详解(7)
- 什么是图形加速卡(四)
- C++ vector容器使用 排序
- 使用ThreadLocal与JDK动态代理 实现事务AOP管理