![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
查找-排序-二分
文章平均质量分 56
查找-排序-二分
master-dragon
weixin:dwl_1270530306
展开
-
04-树9. Path in a Heap (25) -- 小堆树-利用其性质
题目地址:http://www.patest.cn/contests/mooc-ds/04-%E6%A0%919/*04-树9. Path in a Heap (25)http://www.patest.cn/contests/mooc-ds/04-%E6%A0%919节点编号为i的 两个孩子编号 2*i , 2*i+1一个节点编号为i的父节点编号 i/2(i为奇数和偶数都一样)*/#i原创 2015-08-22 16:12:12 · 569 阅读 · 0 评论 -
等差数列
题目描述 Description 给定n(1<=n<=100)个数,从中找出尽可能多的数使得他们能够组成一个等差数列.求最长的等差数列的长度.输入描述 Input Description 第一行是一个整数n,接下来一行包括了n个数,每个数的绝对值不超过10000000.输出描述 Output Description 对于每个输入数据,输出你所找出的最长等差数列的长度样例输入 Sample In原创 2015-08-28 15:45:36 · 877 阅读 · 0 评论 -
1048. Find Coins (25) -- 二分法,寻找和为定值的两个数 (Two Sum - leetcode)
1048. Find Coins (25)时间限制50 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueEva loves to collect coins from all over the uni原创 2015-09-02 15:37:54 · 591 阅读 · 0 评论 -
排序算法问题
关键词时间复杂度 空间复杂度 与初始序列是否相关 最好,最坏,平均 比较次数,移动次数插入排序直接插入每一个元素,与前面的已经排好序的元素进行比较,在移动,插入稳定排序算法(因为可以控制等号)比较次数,移动次数与初始序列有关 最好的比较次数,1 + 1 + 1 … 最差的比较次数 ,1 + 2 + 3 …折半插入排序在直接插入的基础上,与前面的比较的时候可以采用二分法稳定排序算法比较次数原创 2016-09-08 17:08:53 · 1296 阅读 · 0 评论 -
桶排序 -- 相邻最大差值,Maximum Gap(leetcode)
题目描述请设计一个复杂度为O(n)的算法,计算一个未排序数组中排序后相邻元素的最大差值。 给定一个整数数组A和数组的大小n,请返回最大差值。保证数组元素个数大于等于2小于等于500。 测试样例: [9,3,1,10],4 返回:6 http://www.nowcoder.com/practice/376ede61d9654bc09dd7d9fa9a4b0bcd?tpId=49&tqId=2原创 2016-08-09 14:00:44 · 1833 阅读 · 0 评论 -
第k大(小)数,寻找最小的k个数(进一步要求顺序与原数组中元素顺序一致)
分治思想,借用快速排序思路 一趟排序,num个最小的数 在做部分 * 如果 num = k , 则结束 * 如果 num < k , 则在右部分找到 k - num个最小的数 * 如果 num > k , 则继续在左部分找这k个数/************************************** 寻找最小的k个数*****************************原创 2016-06-20 12:12:45 · 1240 阅读 · 0 评论 -
1101. Quick Sort (25) / 1045. 快速排序(25)
题目地址:http://www.patest.cn/contests/pat-a-practise/1101There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then原创 2015-09-18 14:58:43 · 891 阅读 · 0 评论 -
1062. Talent and Virtue (25)
题目地址:http://www.patest.cn/contests/mooc-ds/08-%E6%8E%92%E5%BA%8F3根据题目要求 , 编写合适的比较函数,这里先分类, 不同类直接比较 同类别再一步的比较/*08-排序3. Talent and Virtue (25)http://www.patest.cn/contests/mooc-ds/08-%E6%8E%92%E5%BA%原创 2015-08-24 16:08:13 · 425 阅读 · 0 评论 -
1010. Radix (25)
1010. Radix (25)时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueGiven a pair of positive integers, for example, 6 an原创 2015-11-14 20:18:59 · 539 阅读 · 0 评论 -
leetcode 在有序矩阵中查找某个数,第k小数 (二分法)
240. Search a 2D Matrix II题目地址https://leetcode.com/problems/search-a-2d-matrix-ii/查找特定的某个数,主要是根据矩阵有序,采用二分法缩小矩阵的搜索范围378. Kth Smallest Element in a Sorted Matrix题目地址https://leetcode.com/problems/kth-smal转载 2016-12-13 08:37:54 · 1456 阅读 · 0 评论 -
1098. Insertion or Heap Sort (25) / 1089. Insert or Merge (25)
题目地址:http://www.patest.cn/contests/pat-a-practise/1098/*1098. Insertion or Heap Sort (25)http://www.patest.cn/contests/pat-a-practise/1098*/#include <stdio.h>#include <stdlib.h>#include <math.h>#原创 2015-09-01 14:08:03 · 515 阅读 · 0 评论 -
1055. The World's Richest (25)
题目地址: http://www.patest.cn/contests/pat-a-practise/1055这题需要剪枝(需要仔细读题目),网上参考了之后写的ac代码如下/*1055. The World's Richest (25)http://www.patest.cn/contests/pat-a-practise/1055先进行Person结构体排序;由于题目中M的值小于等于100原创 2015-08-23 15:02:22 · 803 阅读 · 0 评论 -
1085. Perfect Sequence (25) -- 二分法
题目地址https://www.patest.cn/contests/pat-a-practise/1085题目描述Given a sequence of positive integers and another positive integer p. The sequence is said to be a “perfect sequence” if M <= m * p where M and原创 2017-02-12 10:21:06 · 309 阅读 · 0 评论 -
数组小和 归并排序思路 递归、非递归求解
题目描述现定义数组单调和为所有元素i的f(i)值之和。这里的f(i)函数定义为元素i左边(不包括其自身)小于等于它的数字之和。请设计一个高效算法,计算数组的单调和。 给定一个数组A同时给定数组的大小n,请返回数组的单调和。保证数组大小小于等于500,同时保证单调和不会超过int范围。 测试样例: [1,3,5,2,4,6],6 返回:27 http://www.nowcoder.com/p原创 2016-08-10 11:18:46 · 801 阅读 · 0 评论 -
多数组中位数,k大数 -- 二分思路
多数组k大数给定两个有序数组arr1和arr2,在给定一个整数k,返回两个数组的所有数中第K小的数。 例如: arr1 = {1,2,3,4,5}; arr2 = {3,4,5}; K = 1; 因为1为所有数中最小的,所以返回1;arr1 = {1,2,3}; arr2 = {3,4,5,6}; K = 4; 因为3为所有数中第4小的数,所以返回3;要求:如果arr1的长度为N,a原创 2016-08-15 19:02:37 · 1483 阅读 · 0 评论 -
二元组最长递增子序列 -- leetcode 354. Russian Doll Envelopes
leetcode 354. Russian Doll Envelopes题目地址: https://leetcode.com/problems/russian-doll-envelopes/AC代码class Solution {public: int maxEnvelopes(vector<pair<int, int>>& envelopes) { int n = en原创 2016-08-17 10:26:33 · 765 阅读 · 0 评论 -
1056. Mice and Rice (25) 排序 模拟 构造结构体
1056. Mice and Rice (25)题目地址做题的时候可以先模拟一下,主要是构造一个结构体,知道每一层如何操作的,该层结束之后还剩下多少人。这里用到了vector对结构体的不同规则排序 /*http://www.patest.cn/contests/pat-a-practise/10561056. Mice and Rice (25)一次ac*/#include <iostr原创 2015-08-12 15:13:54 · 358 阅读 · 0 评论 -
1085. Perfect Sequence (25)
题目地址: http://www.patest.cn/contests/pat-a-practise/1085Given a sequence of positive integers and another positive integer p. The sequence is said to be a “perfect sequence” if M <= m * p where M and m原创 2015-08-15 17:24:30 · 339 阅读 · 0 评论 -
1080. Graduate Admission (30)
题目地址 http://www.patest.cn/contests/pat-a-practise/1080此题主要是个条件排序, 还用到了 map<>映射,还有如何根据题目构造结构和相关的变量,基本上完全按照要求来,下面是一次ac的代码,没写什么注释 ,不过思路清晰#include <stdio.h>#include <iostream> #include <stdlib.h>#inclu原创 2015-08-14 17:31:19 · 338 阅读 · 0 评论 -
1095. Cars on Campus (30)
题目地址:http://www.patest.cn/contests/pat-a-practise/1095这题处理起来比较繁 下面是24分的代码,可能是题目理解错了#include <stdio.h>#include <stdlib.h>#include <iostream>#include <vector>#include <math.h>#include <string>#inc原创 2015-08-17 15:23:24 · 419 阅读 · 0 评论 -
1029. Median (25)
题目地址:http://www.patest.cn/contests/pat-a-practise/1029 // 就是合并 两个有序数组 的过程/*http://www.patest.cn/contests/pat-a-practise/10291029. Median (25)*/#include <iostream> #include <cstdio> #include <d原创 2015-09-02 14:11:00 · 327 阅读 · 0 评论 -
1075. PAT Judge (25)
题目地址:http://www.patest.cn/contests/pat-a-practise/1075这种题目PAT常考, 就是构造结构体,写比较方法,还有输出的时候要注意题目的要求,把vector<>用会。#include <stdio.h>#include <stdlib.h>#include <iostream>#include <vector>#include <math.h>原创 2015-08-19 14:54:40 · 423 阅读 · 0 评论 -
1080. Graduate Admission (30)
题目地址:http://www.patest.cn/contests/pat-a-practise/1080#include <cstdio> #include <iostream> #include <vector> #include <set>#include <algorithm>#include <stack>#include <string>#include <queue原创 2015-09-03 14:27:14 · 583 阅读 · 0 评论 -
5-5 堆中的路径 (25分) -- 小堆树性质,如何调整
5-5 堆中的路径 (25分)将一系列给定数字插入一个初始为空的小顶堆H[]。随后对任意给定的下标i,打印从H[i]到根结点的路径。输入格式:每组测试第1行包含2个正整数N和M(≤1000),分别是插入元素的个数、以及需要打印的路径条数。下一行给出区间[-10000, 10000]内的N个要被插入一个初始为空的小顶堆的整数。最后一行给出M个下标。输出格式:原创 2015-10-10 10:36:14 · 1788 阅读 · 0 评论 -
5-15 PAT Judge (25分)
5-15 PAT Judge (25分)The ranklist of PAT is generated from the status list, which shows the scores of the submittions. This time you are supposed to generate the ranklist for PAT.Input Sp原创 2015-10-26 09:19:20 · 829 阅读 · 0 评论 -
1012. The Best Rank (25)
1012. The Best Rank (25)时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueTo evaluate the performance of our first yea原创 2015-11-14 21:04:53 · 339 阅读 · 0 评论 -
1025. PAT Ranking (25)
1025. PAT Ranking (25)时间限制200 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueProgramming Ability Test (PAT) is organized by原创 2015-11-22 22:28:22 · 268 阅读 · 0 评论 -
1098. Insertion or Heap Sort (25) 、 1089. Insert or Merge (25)
According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input dat原创 2015-10-26 08:59:20 · 826 阅读 · 0 评论