hdu 1040

6 篇文章 0 订阅

题目传送门

这道题是个排序题目,日常水;写这个这要是学习一下STL的伟大之处。

make_hesp:创建堆

push_heap:加入新元素后更新

pop_heap:推出堆首后更新

sort_heap:排序

参考的博客:点我传送

#include <algorithm>
#include  <iostream>
#include   <cstring>
#include   <stdio.h>
#include    <string>
#include    <vector>
#include     <stack>
#include     <cmath> 
#include     <deque>
#include   	 <queue>
#include       <map>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MOD = 1e9+7;

#define Foru(i,a,b) for(i = a;i < b;i ++)
#define Ford(i,a,b) for(i = a;i > b; i --) 
#define MAXN 100001
int book[1010],num[1010];

bool cmp(int a,int b){
	return a > b;
}

int main(){
	int T,n,i,j,k;
	scanf("%d",&T);
	while(T --){
		scanf("%d",&n);
		Foru(i,0,n){
			scanf("%d",&book[i]);
			push_heap(book,book + i + 1,cmp);
			
		}
//		for(j = 0;j < n ;j ++){
//			printf("%d%c",book[j],j == n-1?'\n':' ');	
//		}
		Foru(i,0,n){
			printf("%d%c",book[0],i == n-1?'\n':' ');
			if(n - i - 1 >= 0)
			pop_heap(book,book + n - i,cmp);
		}
	}
	
	
	return 0;
} 
/*
2
3 2 1 3
9 1 4 7 2 5 8 3 6 9

*/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值