随笔分类 -  各类排序

摘要:1306URAL真是没水题 以为简单的排序就好了 ME 内存限制很紧 堆排序 或者 STL用堆排序做的 正好复习一下 都忘了 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 #define N 1250010 8 int a[N]; 9 void adjust(int i,int n)10 {11 int j;12 a[0] = a[i];13 j = 2*i;14 while(ja[j])17 j++;18 if(a... 阅读全文
posted @ 2013-09-24 09:23 _雨 阅读(236) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3687样例太唬人了,求得是从1到N重量 而不是排好序的标签逆向建图 把最重的赋给第一个入度为0的标签 如有多个赋给标签大的 这样能保证重量大的在后面View Code 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int to[301],w[301][301],de[301],tt[301]; 7 int topo(int n 阅读全文
posted @ 2012-12-06 16:05 _雨 阅读(111) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4380交对的时候 有种被坑的感觉 拓扑就水过去了 实在没想到View Code 1 #include <iostream> 2 #include<cstdio> 3 #include<string.h> 4 using namespace std; 5 int de[2001]; 6 char c[2001][2001]; 7 int main() 8 { 9 int i,j,t,n,m,f,k,kk =0;10 scanf("%d",&t);1 阅读全文
posted @ 2012-08-24 10:02 _雨 阅读(174) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2299求逆序数第一种做法 利用归并排序 在进行两个升序数组归并时 如果右边指针指向的那个数比左边小 那从左边那个位置到mid的数都比右边那个数大 所以比它大的数的个数就是 左边那个数到mid之间的数 依次类推View Code 1 #include <stdio.h> 2 #include <string.h> 3 long long a[500001],num,x[500001],y[500001]; 4 long long msort(long long low,long long mid,long long h 阅读全文
posted @ 2012-07-28 13:22 _雨 阅读(213) 评论(0) 推荐(0)
摘要:就是判断有向图中是否有环 由于开始用dfs搜忘记return了 纠结了一下午 还是经虎学长指点 才找到错误递归View Code 1 #include<stdio.h> 2 #include<string.h> 3 int g[101][101],c[101]; 4 int dfs(int u,int n) 5 { 6 int v; 7 c[u] = -1; 8 for(v = 1 ; v <= n ; v++) 9 if(g[u][v])10 {11 if(c[v]<0)12 {13 ... 阅读全文
posted @ 2012-07-21 20:58 _雨 阅读(288) 评论(0) 推荐(0)
摘要:堆排序 堆排序利用了大根堆(或小根堆)堆顶记录的关键字最大(或最小)这一特征,使得在当前无序区中选取最大(或最小)关键字的记录变得简单。 (1)用大根堆排序的基本思想 ① 先将初始文件R[1..n]建成一个大根堆,此堆为初始的无序区 ② 再将关键字最大的记录R[1](即堆顶)和无序区的最后一个记录R 阅读全文
posted @ 2012-07-21 09:37 _雨 阅读(329) 评论(0) 推荐(0)
摘要:转自http://hi.baidu.com/zhangwp999/blog/item/185f9afba454ba63024f5675.html*六类qsort排序方法P.S.:qsort函数是ANSI C标准中提供的,其声明在stdlib.h文件中,是根据二分发写的,其时间复杂度为n*log(n),其结构为:void qsort(void *base,size_t nelem,size_t width,int (*Comp)(const void *,const void *));其中:*base 为要排序的数组nelem 为要排序的数组的长度width 为数组元素的大小(一字结为单位)(* 阅读全文
posted @ 2012-07-11 23:01 _雨 阅读(352) 评论(0) 推荐(0)