排序
文章平均质量分 52
排序算法
繁星蓝雨
Happy coding!
展开
-
对分段有序的数组排序(前、后部分分别递增)
设m+n个元素顺序存放在数组A[1…m+n]中,前m个元素递增有序,后n个元素递增有序,试设计一个在时间和空间两方面都尽可能高效的算法,使得整个顺序表递增有序。把数组A看作是两个长度分别为m和n的有序表L1、L2,把L2的每个元素依次插入到L1中的合适位置即可。时间复杂度:O(m+n)空间复杂度:O(m+n)时间复杂度:O(mn)空间复杂度:O(1)原创 2023-10-01 20:00:00 · 347 阅读 · 0 评论 -
2016年专业408算法题
因为快排的基准元素元素左边一定小于等于基准元素,基准元素右边的一定大于等于基准元素,故如果中位数小于基准元素,则只对右边的部分继续排序,中位数大于基准元素,则只对左边的部分继续排序。尽可能的大,则需要使划分的两个子集个数尽量想等,较小元素为一个子集,较大元素为一个子集。进行类似快速排序的做法,在处理左右区间时只处理可能包含中位数的区间,即如果区间的范围是。根据前面的思路,对数组进行快速排序得到升序序列,前一个序列取。原创 2023-01-31 20:10:30 · 1371 阅读 · 0 评论 -
第四届蓝桥杯C++B组:三部排序
一般的排序有许多经典算法,如快速排序、希尔排序等。 但实际应用时,经常会或多或少有一些特殊的要求。我们没必要套用那些经典算法,可以根据实际情况建立更好的解法。 比如,对一个整型数组中的数字进行分类排序: 使得负数都靠左端,正数都靠右端,0在中部。注意问题的特点是:负数区域和正数区域内并不要求有序。可以利用这个特点通过1次线性扫描就结束战斗!! ...原创 2019-03-06 10:46:30 · 308 阅读 · 0 评论 -
第九届蓝桥杯C++B组:快速排序
以下代码可以从数组a[]中找出第k小的元素。 它使用了类似快速排序中的分治算法,期望时间复杂度是O(N)的。 请仔细阅读分析源码,填写划线部分缺失的内容。 #include <stdio.h> int quick_select(int a[], int l, int r, int k) { int p = rand() % (r - l + 1) + l; ...原创 2019-03-17 16:59:21 · 554 阅读 · 0 评论 -
1080 Graduate Admission (30 分)
It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admiss...原创 2019-02-28 09:21:07 · 340 阅读 · 0 评论 -
1083 List Grades (25 分)
Given a list ofNstudent records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grad...原创 2019-02-27 21:46:27 · 197 阅读 · 0 评论 -
1075 PAT Judge (25 分)
The ranklist of PAT is generated from the status list, which shows the scores of the submissions(提交). This time you are supposed to generate the ranklist for PAT. Input Specification: Each input ...原创 2019-02-27 19:59:04 · 290 阅读 · 0 评论 -
1055 The World's Richest (25 分)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the peopl...原创 2019-02-26 20:25:59 · 321 阅读 · 0 评论 -
1028 List Sorting (25 分)
Excel can sort records according to any column. Now you are supposed to imitate this function. Input Specification: Each input file contains one test case. For each case, the first line contains two...原创 2019-02-26 18:57:32 · 206 阅读 · 0 评论 -
1025 PAT Ranking (25 分)
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklist...原创 2019-02-24 19:39:18 · 349 阅读 · 0 评论 -
1012 The Best Rank (25 分)
To evaluate the performance of our first year CS majored students, we consider their grades of three courses only:C- C Programming Language,M- Mathematics (Calculus or Linear Algrbra), andE- ...原创 2019-02-25 16:46:40 · 335 阅读 · 0 评论 -
1062 Talent and Virtue (25 分)
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue(美德). According to his theory, a man being outstanding in both talent and ...原创 2019-02-25 11:23:33 · 308 阅读 · 0 评论 -
1016 Phone Bills (25 分)
A long-distance telephone company charges its customers by the following rules: Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. W...原创 2019-02-25 20:57:14 · 385 阅读 · 0 评论 -
1095 Cars on Campus (30 分)
Zhejiang University has 8 campuses(校区) and a lot of gates(大门). From each gate we can collect the in/out times and the plate(拍照) numbers of the cars crossing the gate. Now with all the information avai...原创 2019-02-28 21:08:01 · 726 阅读 · 0 评论 -
1101 Quick Sort (25 point(s))
There is a classical process namedpartitionin the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its le...原创 2019-03-12 10:46:52 · 271 阅读 · 0 评论