随笔分类 -  排序

摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2673排序题刚讲了归并排序就用归并排序做View Code 1 #include<stdio.h> 2 void qsort(int a[],int l,int r) 3 { 4 int x=a[l],i=l,j=r; 5 if(l>=r)return; 6 while(i<j) 7 { 8 while(i<=j&&a[j]>=x) 9 j--;10 a[i]=a[j];11 while(i<j&&a[i... 阅读全文
posted @ 2012-08-03 19:48 时光旅行的懒猫 阅读(265) 评论(0) 推荐(0)
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1106题目难点在分割整数吧,快排可以套用模板。方法1 快排View Code 1 #include<stdio.h> 2 char str[1010]; 3 int a[100000]; 4 void qsort(int a[],int l,int r) 5 { 6 int x=a[l],i=l,j=r; 7 if(l>=r) return; 8 while(i<j) 9 {10 while(i<j&&a[j]>=x)j--;11 a[... 阅读全文
posted @ 2012-08-03 18:39 时光旅行的懒猫 阅读(311) 评论(0) 推荐(0)
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1031题意 先按满意度排序,再按序号输出。思路 数据量并不大 用个结构体,用一般的排序就可以。View Code 1 #include<stdio.h> 2 #include<string.h> 3 struct s 4 { 5 int num; 6 double mark; 7 }a[1000],t; 8 int main() 9 {10 int n,m,k,i,j,o,s;11 double d;12 while(~scanf("%d %d %d",&a 阅读全文
posted @ 2012-08-03 18:32 时光旅行的懒猫 阅读(285) 评论(0) 推荐(0)
摘要:题目链接http://acm.timus.ru/problem.aspx?space=1&num=1100思路 结构体的二级排序 不过要按照先输入先输出的顺序。因此可以先给它赋上编号。然后如果相等的话,按照编号来进行二级排序。先输出编号小的。View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 struct in 4 { 5 int id; 6 int m; 7 int num; 8 }ss[150001]; 9 int cmp(const void *a,const void *b)10 {11 struct 阅读全文
posted @ 2012-08-03 18:18 时光旅行的懒猫 阅读(250) 评论(0) 推荐(0)
摘要:堆排序题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1425关于堆排序讲解详看http://www.cnblogs.com/dolphin0520/archive/2011/10/06/2199741.html代码跑了562MS 实在是仰慕用93MS跑出来的这个题还必须用C交 用GCC交会TLEView Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #define N 1000005 5 int a[N]; 6 vo 阅读全文
posted @ 2012-07-21 18:54 时光旅行的懒猫 阅读(354) 评论(0) 推荐(0)