
排序
不可不戒
这个作者很懒,什么都没留下…
展开
-
xmu 1229.Sherwood算法——二叉排序树
#include #include int length;int a[100001];void Exchange(int *a,int *b){ int temp=*a; *a=*b; *b=temp;}void Min_Heapify(int a[],int i)//保持最小堆性{ int l=i*2,r=i*2+1原创 2012-07-18 20:50:00 · 567 阅读 · 0 评论 -
相邻最大差值
题目描述请设计一个复杂度为O(n)的算法,计算一个未排序数组中排序后相邻元素的最大差值。 给定一个整数数组A和数组的大小n,请返回最大差值。保证数组元素个数大于等于2小于等于500。 测试样例: [9,3,1,10],4 返回:6/** * 桶排序 * 数组元素映射到桶 * 相邻最大差值 = 连续空桶最多 + 1 * @param A * @原创 2016-07-29 16:00:12 · 1135 阅读 · 0 评论 -
hdu1872 稳定排序
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1872#include #include #include #define MAXN 302using namespace std;typedef struct node{ int id,score; char name[52];}Student;int cmp(co原创 2013-09-05 17:02:16 · 706 阅读 · 0 评论 -
hdu1236 排名
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1236#include #include #include #define MAXN 1002using namespace std;struct node{ char id[21]; int score;}stu[MAXN];int cmp(const node &原创 2013-09-03 12:28:14 · 689 阅读 · 0 评论 -
hdu1031 Design T-Shirt
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1031简单排序。#include #include #define MAXN 10002using namespace std;struct node{ int no; float val;}elem[MAXN];int cmp1(node x,node y原创 2013-08-10 09:25:26 · 1083 阅读 · 0 评论 -
hdu3785 寻找大富翁
#include #include #define MAXN 100002//排序int arr[MAXN];int cmp(const void *x,const void *y){ return *(int *)y-*(int *)x;}int main(){ int n,m,i; while(scanf("%d %d",&n,&m)&&n) { for(i=原创 2013-07-29 11:55:48 · 749 阅读 · 0 评论 -
错排问题 xmu 1052.False
定义: n个有序的元素应有n!个不同的排列,如若一个排列使得所有的元素不在原来的位置上,则称这个排列为错排,有的叫重排。1 2 3 4的错排有4 3 2 1,4 1 2 3,4 3 1 2,3 4 1 2,3 4 2 1,2 4 1 3,2 1 4 3,3 1 4 2,2 3 4 1。第一列是4分别与1,2,3互换位置,其余两个元素错排.由此生成的。转载 2012-07-12 21:56:02 · 750 阅读 · 0 评论 -
hdu1394 Minimum Inversion Number 归并排序
#include #include#include #define MAXNUM 5010int arr[MAXNUM]={0};int arr_temp[MAXNUM];int arr1[MAXNUM];int ans;//归并排序,写的有点乱void merge(int left,int middle,int right){ int i,j,k; i=left;j=m原创 2013-07-14 00:51:33 · 864 阅读 · 2 评论 -
hdu1873 看病要排队
//c++ STL就是好用,不会c++,写的蛋疼啊//转发#include #include #include using namespace std;struct node{ int id,num; friend bool operator < (node a,node b) { if(a.num!=b.num) return a.num<b.num; else转载 2013-07-11 19:04:04 · 784 阅读 · 0 评论 -
hdu 1425.sort
#include using namespace std; bool num[1000001]; int main() { int n,m,i,j,a; while(scanf("%d %d",&n,&m)!=EOF){ for(i=0;i scanf("%d",&a);转载 2012-07-28 15:22:36 · 463 阅读 · 0 评论 -
xmu 1328.不高兴的bobo
#include #include#define MAXNUM 1000002int arr[MAXNUM]={0};int arr_temp[MAXNUM];long long ans;//归并排序void merge(int left,int middle,int right){ int i,j,k; i=left;j=middle+1;k=0; while (i<=m原创 2013-05-18 23:23:34 · 766 阅读 · 0 评论 -
xmu-1315 哈夫曼编码问题
#include #include #include #define MAX 200 long a[MAX],a1[MAX]; char str[100001]; long n,length; void Exchange(long *a,long *b) { long temp=*a; *a=*b;原创 2012-05-26 23:42:24 · 612 阅读 · 0 评论 -
hdu1871 无题
#include #include int n;struct node{ int No; int num; int price;}hotel[1002];int cmp(const void *a,const void *b){ struct node *x=(node *)a; struct node *y=(node *)b; if(x->price-y->pri原创 2013-07-10 18:40:40 · 864 阅读 · 0 评论 -
堆排序
1.堆 堆实际上是一棵完全二叉树,其任何一非叶节点满足性质: Key[i]<=key[2i+1]&&Key[i]<=key[2i+2]或者Key[i]>=Key[2i+1]&&key>=key[2i+2] 即任何一非叶节点的关键字不大于或者不小于其左右孩子节点的关键字。 堆分为大顶堆和小顶堆,满足Key[i]>=Key[2i+1]&&key>=key[2i+2]称为大顶堆,满原创 2016-08-18 20:09:07 · 318 阅读 · 0 评论