1306. Sorting Algorithm

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

One of the fundamental problems of computer science is ordering a list of items. There're a plethora of solutions to this problem, known as sorting algorithms. Some sorting algorithms are simple and intuitive, such as the bubble sort. Others, such as the heap sort are not so simple, but produce lightening-fast results.

In the following is a list of some sorting algorithms. Of course, I can’t tell you how to implement them here. You must use your own knowledge.


Bubble sort

Heap sort

Insertion sort

Merge sort

Quick sort

Selection sort

Shell sort


My business here is to give you some numbers, and to sort them is your business. Attention, I want the smallest number at the top of the sorted list.

Input

The input file will consist of series data sets. Each data set has two parts. The first part contains two non-negative integers, n (1≤n≤100,000) and m (1≤m≤n), representing the total of numbers you will get and interval of the output sorted list. The second part contains n positive integers. I am sure that each integer in this part will be less than 2,000,000,000.

The input is terminated by a line with two zeros.

Output

For one data set, you should output several numbers in ONE line. After you get the sorted list, you should output the first number of each m numbers, and you should print exact ONE space between two adjacent numbers. And please make sure that there should NOT be any blank line between outputs of two adjacent data sets.

Sample Input

8 2
3
5
7
1
8
6
4
2
0 0

Sample Output

1 3 5 7

Problem Source

ZSUACM Team Member

#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
priority_queue< int,vector<int>,greater<int> > que;
int main(){
int n,m;
while(cin>>n>>m&&n!=&&m!=){
int a;
for(int i=;i<n;i++){
cin>>a;
que.push(a);
}
int t = que.top();
cout<<t;
que.pop();
int cnt = ;
while(!que.empty()){
int t = que.top();
que.pop();
if(cnt%m==){
cout<<' '<<t;
}
cnt = (cnt+)%m;
}
cout<<endl;
}
return ;
}

1306. Sorting Algorithm 2016 12 30的更多相关文章

  1. U3D笔记11:47 2016/11/30-15:15 2016/12/19

    11:47 2016/11/30Before you can load a level you have to add it to the list of levels used in the gam ...

  2. My latest news(--2016.12.31)

    2016.12.31  前一天晚上看 “纪实新闻” ,白天看视频,晚上刷题,看电影<湄公河行动> 2016.12.30 18:36 昨天上午考完了本学期的最后一门课程,下午乒乓+值班,今天 ...

  3. Understand:高效代码静态分析神器详解(一) | 墨香博客 http://www.codemx.cn/2016/04/30/Understand01/

    Understand:高效代码静态分析神器详解(一) | 墨香博客 http://www.codemx.cn/2016/04/30/Understand01/ ===== 之前用Windows系统,一 ...

  4. 2018.12.30【NOIP提高组】模拟赛C组总结

    2018.12.30[NOIP提高组]模拟赛C组总结 今天成功回归开始做比赛 感觉十分良(zhōng)好(chà). 统计数字(count.pas/c/cpp) 字符串的展开(expand.pas/c ...

  5. mysql查询练习题-2016.12.16

    >>>>>>>>>> 练习时间:2016.12.16 编辑时间:2016-12-20-->22:12:08 题: 涉及:多表查询.ex ...

  6. 关于2016.12.12——T1的反思:凸包的意义与应用

    2016.12.12 T1 给n个圆,保证圆圆相离,求将圆围起来的最小周长.n<=100 就像上图.考场上,我就想用切线的角度来做凸包.以圆心x,y排序,像点凸包一样,不过用两圆之间的下切线角度 ...

  7. rhel 7.0 配置centos yum源(2016/12/8),成功!

    1.首先查看redhat 7.0系统本身所安装的那些yum 软件包: rpm -qa | grep yum #列出所有已安装的yum包 2.删除这些包: rpm -e *.rpm --nodeps # ...

  8. 更新日志(建议升级到2016.12.17) && 更新程序的方法

    更新程序的方法: 1,在控制面板里点击备份当前数据库文件到磁盘,把当天获取的信息从内存写到磁盘/存储卡.2,下载最新版的源码 wget -O "infopi.zip" " ...

  9. Oracle中把一个DateTime的字符串转化成date类型。to_date('2016/12/8 18:55:43','yyyy/MM/dd hh24:mi:ss'),

    Oracle中把一个DateTime或者该形态字符串转化成date类型. to_date('2016/12/8 18:55:43','yyyy/MM/dd hh24:mi:ss'), 或者: sele ...

随机推荐

  1. CSS3制作同心圆进度条

    1.css代码 此处在制作进度条时,是旋转进度条的半圆(红色),背景使用灰白(如果使用红色作为背景,旋转灰白遮罩,在浏览器中可能会有渲染bug) .wrapper{ display:block;pos ...

  2. 【原】相煎何太急——input的blur事件与button的click事件

    先来一段引子,最近在写手机h5页面,主要是一些登陆注册方面的,最绕不开的就是表单元素. 我想实现的是:在输入框后边有一个删除图标,当输入东西的时候触发事件,显示删除图标,点击该图标会删除之前输入的内容 ...

  3. 博客代码:iframe—网页中嵌入其他网页

    iframe 是一个可以把另外一个网页嵌入到一个网页里的代码,非常有用.对于一个内容不错的网页,要方便地把它搬到自己的博客里,用这个代码最合适.而对于在新浪博客里不支持的一些网页效果和代码,可先把他们 ...

  4. 基于VLC的视频播放器(转载)

    最近在研究视频播放的功能,之前是使用VideoView.在网上看了一下,感觉不是很好,支持的格式比较少,现在网络视频的格式各种各样,感觉用VideoView播放起来局限性很大. 找到了一个比较合适的播 ...

  5. excel 导入 sqlserver 字符串被截取为255长度解决方案

    excel表格导入sqlserver数据表中 内容被截取为255长度的字符串. 注意:excel是通过前8行(表头的首行除外)的数据类型来判断导入数据的数据格式的,例如前8行出现整数型,那么默认就用整 ...

  6. Struts2,Spring, Hibernate三大框架SSH的整合步骤

    整合步骤 创建web工程 引入相应的jar包 整合spring和hibernate框架 编写实体类pojo和hbm.xml文件 编写bean-base.xml文件 <!-- 1) 连接池实例 - ...

  7. excel中的TEXT函数

    TEXT 函数可将数值转换为文本,并可使用户通过使用特殊格式字符串来指定显示格式. TEXT(value, format_text) value  必需.数值.计算结果为数值的公式,或对包含数值的单元 ...

  8. 【NoSql】Redis

    [NoSql]Redis 一. 文档 1. 官网 2. Windows 安装包 3. C# Driver a. ServiceStack.Redis 最新版本是收费的 b. StackExchange ...

  9. LDAP与jenkins

    1:下载:jenkins.war 2:运行:java -jar jenkins.war  一直让他开着,后者放到后台进程 3:在浏览器输入http://IP:8080   4:设置LDAP     若 ...

  10. [OC笔记]@property之个人理解,大神轻拍

    /** * 一个简单的对象 * * @author suzhen * */ public class SimpleObjcet { /** * 声明一个age字段 */ private Object ...