- 博客(23)
- 资源 (8)
- 收藏
- 关注
原创 【算法学习】康托展开(全排列中某一排列的字典序计算问题)
文章目录一、康托展开介绍二、手动计算Cantor展开三、代码模板这也是排列组合中的一个问题,不是【搜索】的技巧,但也有一定的关系,可以简化搜索状态的复杂度。如果,在某一个问题中,我们想知道一个排列是否出现过,由于全排列有N!个,我们一一比对,要O(N!)的复杂度。这就会拖累整体算法。下面我们运用一种方法——康托展开,用O(N!)个bool的空间,得到O(N2)的复杂度。一、康托展开介绍康...
2020-02-28 15:52:46 483
原创 LeetCode C++ 206. Reverse Linked List【LinkedList】【链表反转】
Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLFollow up:A linked list can be reversed either iteratively or recursively...
2020-02-23 21:24:17 256
原创 HDU 1362 Red and Black【BFS/DFS】
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 33879 Accepted Submission(s): 20528Problem DescriptionThere is a rectangular room, cover...
2020-02-23 16:33:32 233
原创 LeetCode C++ 232. Implement Queue using Stacks【Queue】【使用栈实现队列】
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(...
2020-02-23 14:19:39 188
原创 LeetCode C++ 225. Implement Stack using Queues 【Stack】【使用队列实现栈】
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet...
2020-02-23 14:19:02 263
原创 LeetCode C++ 26. Remove Duplicates from Sorted Array【Array/Two Pointers】【快慢指针】
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modifyin...
2020-02-22 22:10:17 160
原创 LeetCode C++ 27. Remove Element【Array/Two Pointers】【快慢指针】
Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input array...
2020-02-22 19:16:09 220
原创 LeetCode C++ 74. Search a 2D Matrix【Array/BinarySearch】【medium】
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row ...
2020-02-22 16:12:33 181
原创 ? LeetCode C++ 75. Sort Colors 【Array/Two Pointers/Sort】【三路排序】【medium】
Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the int...
2020-02-22 00:54:06 251
原创 LeetCode C++ 283. Move Zeroes【Array/Two Pointers】简单
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]Note:You must d...
2020-02-21 15:36:28 236
原创 【二分图】LeetCode C++ 785. Is Graph Bipartite? 【Medium】
Given an undirected graph, return true if and only if it is bipartite.Recall that a graph is bipartite if we can split it's set of nodes into two independent subsets A and B such that every edge in t...
2020-02-21 00:19:00 380
原创 洛谷 P1618 三连击(升级版)
将 1,2,…,9 共 9 个数分成三组,分别组成三个三位数,且使这三个三位数的比例是 A:B:C,试求出所有满足条件的三个三位数,若无解,输出No!!!。输入格式三个数,A,B,C。输出格式若干行,每行 3 个数字。按照每行第一个数字升序排列。输入输出样例输入 #11 2 3输出 #1192 384 576219 438 657273 546 819327 654 ...
2020-02-18 16:23:28 209
原创 洛谷 P1478 陶陶摘苹果(升级版)【贪心】
题目描述又是一年秋季时,陶陶家的苹果树结了n个果子。陶陶又跑去摘苹果,这次他有一个 a 公分的椅子。当他手够不着时,他会站到椅子上再试试。这次与 NOIp2005 普及组第一题不同的是:陶陶之前搬凳子,力气只剩下 s 了。当然,每次摘苹果时都要用一定的力气。陶陶想知道在 s<0 之前最多能摘到多少个苹果。现在已知 n 个苹果到达地上的高度 xi,椅子的高度 a,陶陶手伸直的最大长度 b...
2020-02-18 13:25:17 578
原创 LeetCode C++ 228. Summary Ranges 【Array】
Given a sorted integer array without duplicates, return the summary of its ranges.Example 1:Input: [0,1,2,4,5,7]Output: ["0->2","4->5","7"]Explanation: 0,1,2 form a continuous range; 4,5 fo...
2020-02-17 21:55:43 284
原创 基础编程题目集 编程题部分
★★ 7-22 龟兔赛跑 (20分)★★★ 7-23 币值转换 (20分) 中文习惯读数字 【约瑟夫环】7-28 猴子选大王 (20分)★ 7-29 删除字符串中的子串 (20分)★★★ 7-37 整数分解为若干项之和 (20分)★★★ 7-38 数列求和-加强版 (20分)
2020-02-17 16:31:22 6122 4
原创 浙大版《C语言程序设计(第3版)》题目集 函数题部分 45道
文章目录练习5-1 求m到n之和 (10分)练习5-2 找两个数中最大者 (10分)练习5-3 数字金字塔 (15分)习题5-1 符号函数 (10分)习题5-2 使用函数求奇数和 (15分)习题5-3 使用函数计算两点间的距离 (10分)练习5-1 求m到n之和 (10分)本题要求实现一个计算m~n(m<n)之间所有整数的和的简单函数。函数接口定义:int sum( int m, i...
2020-02-16 01:45:15 17095 13
原创 LeetCode C++ 303. Range Sum Query - Immutable 【Array/一维前缀和】
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRan...
2020-02-15 18:30:14 291
原创 【约瑟夫环】HDU 1276 士兵队列训练问题
Problem Description某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行一至三报数,凡报到三的出列,剩下的向小序号方向靠拢,继续从头开始进行一至二报数。。。,以后从头开始轮流进行一至二报数、一至三报数直到剩下的人数不超过三人为止。Input本题有多个测试数据组,第一行...
2020-02-14 23:39:24 442
原创 【约瑟夫环】PTA 基础编程题目集 编程题部分 7-28 猴子选大王 (20分)
一群猴子要选新猴王。新猴王的选择方法是:让N只候选猴子围成一圈,从某位置起顺序编号为1~N号。从第1号开始报数,每轮从1报到3,凡报到3的猴子即退出圈子,接着又从紧邻的下一只猴子开始同样的报数。如此不断循环,最后剩下的一只猴子就选为猴王。请问是原来第几号猴子当选猴王?输入格式:输入在一行中给一个正整数N(≤1000)。输出格式:在一行中输出当选猴王的编号。输入样例:11输出样例:...
2020-02-14 15:39:58 1008
原创 LeetCode C++ 448. Find All Numbers Disappeared in an Array【Array/Hash Table】简单
6-10 阶乘计算升级版 (20分)本题要求实现一个打印非负整数阶乘的函数。函数接口定义:void Print_Factorial ( const int N );其中N是用户传入的参数,其值不超过1000。如果N是非负整数,则该函数必须在一行中打印出N!的值,否则打印“Invalid input”。裁判测试程序样例:#include <stdio.h>void Pr...
2020-02-14 12:43:31 258
原创 LeetCode C++ 404. Sum of Left Leaves 【Tree】
404. Sum of Left Leaves 【easy】Find the sum of all left leaves in a given binary tree.Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and...
2020-02-13 18:22:29 231
原创 LeetCode 414. Third Maximum Number【数组】简单
414. Third Maximum Number 【easy】Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n...
2020-02-13 13:44:51 298
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人