1306. Sorting Algorithm 2016 12 30
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的更多相关文章
- 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 ...
- My latest news(--2016.12.31)
2016.12.31 前一天晚上看 “纪实新闻” ,白天看视频,晚上刷题,看电影<湄公河行动> 2016.12.30 18:36 昨天上午考完了本学期的最后一门课程,下午乒乓+值班,今天 ...
- Understand:高效代码静态分析神器详解(一) | 墨香博客 http://www.codemx.cn/2016/04/30/Understand01/
Understand:高效代码静态分析神器详解(一) | 墨香博客 http://www.codemx.cn/2016/04/30/Understand01/ ===== 之前用Windows系统,一 ...
- 2018.12.30【NOIP提高组】模拟赛C组总结
2018.12.30[NOIP提高组]模拟赛C组总结 今天成功回归开始做比赛 感觉十分良(zhōng)好(chà). 统计数字(count.pas/c/cpp) 字符串的展开(expand.pas/c ...
- mysql查询练习题-2016.12.16
>>>>>>>>>> 练习时间:2016.12.16 编辑时间:2016-12-20-->22:12:08 题: 涉及:多表查询.ex ...
- 关于2016.12.12——T1的反思:凸包的意义与应用
2016.12.12 T1 给n个圆,保证圆圆相离,求将圆围起来的最小周长.n<=100 就像上图.考场上,我就想用切线的角度来做凸包.以圆心x,y排序,像点凸包一样,不过用两圆之间的下切线角度 ...
- rhel 7.0 配置centos yum源(2016/12/8),成功!
1.首先查看redhat 7.0系统本身所安装的那些yum 软件包: rpm -qa | grep yum #列出所有已安装的yum包 2.删除这些包: rpm -e *.rpm --nodeps # ...
- 更新日志(建议升级到2016.12.17) && 更新程序的方法
更新程序的方法: 1,在控制面板里点击备份当前数据库文件到磁盘,把当天获取的信息从内存写到磁盘/存储卡.2,下载最新版的源码 wget -O "infopi.zip" " ...
- 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 ...
随机推荐
- linux 驱动学习笔记04--简单驱动
首先贴代码helloworld.c和Makefile /************************************************************************ ...
- Python 无限循环
import threading import time class CountDownTimer(threading.Thread): def __init__(self, seconds, act ...
- redis启用持久化
redis的持久化有rdb和aof两种. rdb是记录一段时间内的操作,一盘的配置是一段时间内操作超过多少次就持久化. aof可以实现每次操作都持久化. 这里我们使用aof. 配置方式,打开redis ...
- [转载] 深入理解Android之Java虚拟机Dalvik
本文转载自: http://blog.csdn.net/innost/article/details/50377905 一.背景 这个选题很大,但并不是一开始就有这么高大上的追求.最初之时,只是源于对 ...
- StringUtils方法全集
org.apache.commons.lang.StringUtils中方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的( ...
- 如何向新手程序员介绍Java编程
学习Java,他们都说很easy. 作为一名刚从斯康星大学麦迪逊分校计算机科学系毕业的大学生,我通过一些编程课程认识了很多使用Java的朋友.现在很多学校都在从别的编程语言(大多是C ++)转教Jav ...
- Android——数据的存储和访问
1.数据文件的存取操作 我们可以将数据存取在Android应用数据的默认存储地址,其地址为:安装包/data/data/<package name>/files/ 1)向文件中写入数据 p ...
- iOS 上架被拒原因保存
一.后台一直在获取用户的定位,需要给用户电池消耗提示 Your app uses the Location Background mode but does not include the requi ...
- OAuth 2.0 Threat Model and Security Considerations (rfc6819)
Authorization server The following data elements are stored or accessible on the authorization serve ...
- Java 枚举7种常见用法
(转)原创地址:http://blog.lichengwu.cn/java/2011/09/26/the-usage-of-enum-in-java/ JDK1.5引入了新的类型--枚举.在 Java ...