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. oracle 异常

    ORACLE 异常错误处理 本篇主要内容如下: 5.1 异常处理概念 5.1.1 预定义的异常处理 5.1.2 非预定义的异常处理 5.1.3 用户自定义的异常处理 5.1.4  用户定义的异常处理 ...

  2. 学习shell脚本笔记

    1.if 是单分支语句,使用格式如下: if condition ; then statement ….. fi 2.if … else 是双分支语句,使用格式如下: if condition ; t ...

  3. css中外边距合并

    最近在布局时遇到一个有趣的问题 <style> #div1{width:200px;height:200px;background:red;}  #div2{width:50px;heig ...

  4. cdnbest的站点设置里设置url跳转设置

    示例: 内容示例写法: ^http://kangleweb.com/(.*)$ https://www.kangleweb.com/$1 这只是一个例子,其他用法您可以自已多试试

  5. openssl和Java的keytool证书相关的命令总结

    Java的keytool keytool -genkey -alias myserver -keyalg RSA -keysize -keystore oauth-server.keystore -v ...

  6. Node.js intro

    1. require() load module http://stackoverflow.com/questions/9901082/what-is-this-javascript-require ...

  7. 转发(forward)和重定向(sendRedirect)

    一. RequestDispatche 是一个Web资源的包装器,可以用来把当前的Request传递给该资源,或者把新的资源包括到当前的相应中.详细来说:RequestDispatch对象从客户端获取 ...

  8. php emoji处理微信表情

    使用 https://github.com/iamcal/php-emoji 添加下面的函数到代码中 function utf8_bytes($cp){ if ($cp > 0x10000){ ...

  9. [刘阳Java]_MyBatis_动态SQL标签用法_第7讲

    1.MyBatis的动态SQL是基于OGNL表达式的,它可以帮助我们方便的在SQL语句中实现某些逻辑. 2.MyBatis中用于实现动态SQL的元素主要有 if choose(when,otherwi ...

  10. JavaScript之作用域和引用类型

    学习js高级程序设计第四.五章 4.1基本类型和引用类型的值:基本类型值指的是简单的数据段,引用类型值指可能由多个值构成的对象. 引用类型的值是保存在内存中的对象,不能直接访问,而是按引用访问(类似指 ...