![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 70
Vilinzz
这个作者很懒,什么都没留下…
展开
-
Capacitated Facility Location Problem
Capacitated Facility Location Problem题目要求Suppose there are n facilities and m customers. We wish to choose:which of the n facilities to open.the assignment of customers to facilities.The objec...原创 2018-12-22 14:29:25 · 1376 阅读 · 0 评论 -
LeetCode--Keys and Rooms
Keys and Rooms题目There are N rooms and you start in room 0. Each room has a distinct number in 0, 1, 2, …, N-1, and each room may have some keys to access the next room.Formally, each room i has a ...原创 2018-10-14 22:20:26 · 153 阅读 · 0 评论 -
算法设计与分析第四周练习(图论)
Network Delay Time1. 题目There are N network nodes, labelled 1 to N.Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the target node, and ...原创 2018-09-28 13:54:57 · 346 阅读 · 0 评论 -
LeetCode--String to Integer (atoi)
String to Integer (atoi)1 题目Implementatoiwhichconverts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character i...原创 2018-09-22 10:42:26 · 189 阅读 · 0 评论 -
算法分析与设计第三周练习(图论)
目录Evaluate DivisionReconstruct Itinerary总结Evaluate Division1. 题目Equations are given in the formatA / B = k, whereAandBare variables represented as strings, andkis a real number (flo...原创 2018-09-21 23:07:40 · 346 阅读 · 0 评论 -
算法设计与分析(五)
Is Graph Bipartite?1. 题目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...原创 2018-10-04 10:04:31 · 195 阅读 · 0 评论 -
算法设计与分析(六
Merge k Sorted Lists题目Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[1->4->5,1->3->4,2->6]Output: 1->1-&gt原创 2018-10-11 19:30:11 · 151 阅读 · 0 评论 -
LeetCode--Search a 2D Matrix II(分治策略)
Search a 2D Matrix II题目Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted in ascending from left ...原创 2018-09-15 14:30:52 · 254 阅读 · 0 评论 -
LeetCode--Merge k Sorted Lists--分治策略
Merge k Sorted Lists--分治策略题目Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.ExampleInput:[ 1->4->5, 1->3->4, 2->6]Out...原创 2018-09-14 23:26:37 · 137 阅读 · 0 评论 -
算法设计与分析(七)
贪心算法题目这次我们选择两题贪心算法作为练习,这两道题目是有关系的,一个是比较基础的贪心,另一个是难一点的贪心。Jump GameGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array re...原创 2018-10-18 23:46:51 · 180 阅读 · 0 评论 -
算法设计与分析--动态规划(八)
Longest Increasing Path in a Matrix题目Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may...原创 2018-10-27 11:37:18 · 231 阅读 · 0 评论 -
算法设计与分析(九)--动态规划
Burst Balloons题目Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i yo...原创 2018-10-30 22:14:53 · 256 阅读 · 0 评论 -
算法设计与分析(十四)
Maximum Product Subarray题目Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Outpu...原创 2018-12-09 14:30:55 · 499 阅读 · 0 评论 -
算法设计与分析(十三)
Count of Range Sum题目Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the sum of the elements in nums between indices...原创 2018-11-27 21:45:08 · 428 阅读 · 0 评论 -
算法设计与分析(十二)--动态规划
Target Sum题目You are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.Fin...原创 2018-11-25 00:16:28 · 275 阅读 · 0 评论 -
算法设计与分析(十一)--动态规划
1. Unique Binary Search Trees2. Unique Binary Search Trees IIUnique Binary Search Trees题目Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n?分析这题是典型的卡特兰数的例...原创 2018-11-16 19:22:14 · 216 阅读 · 0 评论 -
算法设计与分析--动态规划(十)
Scramble String题目Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = “great”:great/ ...原创 2018-11-08 13:24:14 · 520 阅读 · 0 评论 -
Edit Distance(动态规划)
Edit Distance题目Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert a character...原创 2018-11-04 15:15:43 · 1577 阅读 · 1 评论 -
Unique Paths II(动态规划)
Unique Paths II题目A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is tryi...原创 2018-11-04 14:28:08 · 245 阅读 · 0 评论 -
Longest Valid Parentheses(动态规划)
Longest Valid Parentheses题目Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.Example 1:Input: “(()”Output: 2Expl...原创 2018-11-04 13:33:37 · 475 阅读 · 0 评论 -
算法设计与分析第二周练习
目录Course Schedule(拓扑) Kth Largest Element in an Array(分治算法)Kth Largest Element in an Array题目Find the kth largest element in an unsorted array. Note that it is the kth largest element in the s...原创 2018-09-14 18:50:27 · 266 阅读 · 0 评论 -
3Sum
3Sum1.题目Given an arraynumsofnintegers, are there elementsa,b,cinnumssuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set m...原创 2018-09-24 23:49:16 · 155 阅读 · 0 评论 -
LeetCode--Longest Common Prefix
Longest Common Prefix题目Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string"".Example 1:Input: ["flowe...原创 2018-09-24 21:08:58 · 163 阅读 · 0 评论 -
排序方法(数据结构)
经典排序算法 经典排序算法,以下文章参考了大量网上的资料,大部分都给出了出处这一系列重点在理解,所以例子什么的都是最简单的情况,难免失误之处,多指教大多数排序算法都给出了每一步的状态,以方便初学者更容易理解,通俗易懂,部分难以理解的排序算法则给出了大量的图示,也算是一个特色吧经典排序算法 - 快速排序Quick sort经典排序算法 - 桶排序Bucket sort经典排序算法 - 插入转载 2018-01-03 21:32:45 · 161 阅读 · 0 评论 -
n个数的出栈方式(卡特兰数)
问题给定n个数,有多少种出栈序列,进栈是按照顺序进栈?分析:当n为1时: f(1) = 1 //即 1 当n为2时: f(2) = 2;//12, 21 当n为3时: f(3) = 5;//123,132,213,321,231 当n为4的时候:当a第一个出栈的时候,bcd的进栈与出栈的方式与n=3的时候是一样的,是它的子问题,此时有f(3)种不同结果。原创 2018-01-03 00:52:11 · 1938 阅读 · 0 评论 -
Ordering Tasks(优先工作)拓补排序
Ordering Tasks工具queuevector思路主要是处理好每个点的入度的关系,当一个节点的前驱节点全部被处理的时候,表示该节点能被处理,每处理一个节点,他对应的后序节点的入度都减1#include <iostream>#include <vector>#include <string>#include <queue>#include <memory.h>using nam原创 2017-12-24 21:34:01 · 793 阅读 · 0 评论 -
A-B差集(即在A但不在B的数)
A B的差集思路:对于这个查找的题,如果用一般的循环去查找,时间复杂度为O(n2),肯定是不能Accepted的,那么我们是否可以将时间复杂度降低到O(n)呢?为了达到这个目的,我们需要用到下面的容器 1. set 2. vector思路首先用两个vector存好输入的数据将两个vector的数据转化为set的数据,由于set的自动去重功能,次数set的数据都是唯一的。我们每次将set1中原创 2017-12-24 15:16:52 · 1039 阅读 · 0 评论 -
实现栈和队列的不同方法
实现栈和队列的不同方法本博客通过顺序和链式两种方式分别去实现了栈和队列,仅供参考//main.cpp#include <iostream>#include "source.hpp"#include "arrayOfStack.hpp"#include "arrayOfQueue.hpp"#include "linkOfStack.hpp"#include "LinkOfQueue.hpp原创 2017-09-23 23:29:27 · 255 阅读 · 0 评论 -
统计数字出现次数
Description 某次科研调查时得到了n个自然数,每个数均不超过1500000000(1.5*10^9)。已知不相同的数不超过10000个,现在需要统计这些自然数各自出现的次数,并按照自然数从小到大的顺序输出统计结果。 Input 包含多个测试数据,每个包含n+1行: 第1行是整数n,表示自然数的个数。 第2~n+1行每行一个自然数。原创 2017-12-24 14:50:23 · 4782 阅读 · 0 评论 -
寻找第k大数字(numberk)
Time Limit: 10sec Memory Limit:256MB Description 经过长时间的筹备工作,在Jourk,Ronny,Plipala,阿长,阿沈等人的努力下,DM实验室建立起自己的系列网站,其中包括三个大板块:DMOJ首页、DMOJ论坛、DMOJ博客。 作为一个大型的网站,数据的加工处理需要用到很多算法系统模块,通过这些模块对系统主数据库进行修改原创 2017-12-24 14:44:22 · 974 阅读 · 0 评论 -
LeetCode--3Sum Closest
3Sum Closest题目Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume th...原创 2018-09-07 20:18:36 · 181 阅读 · 0 评论 -
LeetCode--Two Sum
Two Sum题目Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not ...原创 2018-09-08 10:57:29 · 123 阅读 · 0 评论 -
LeetCode--Add Two Numbers
Add Two Numbers题目You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two...原创 2018-09-08 14:02:46 · 158 阅读 · 0 评论 -
LeetCode--Integer to Roman
Integer to Roman1. 题目Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C ...原创 2018-09-23 23:16:13 · 174 阅读 · 0 评论 -
LeetCode--Roman to Integer
Roman to Integer1. 题目Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM.Symbol ValueI 1V 5X 10L 50C ...原创 2018-09-23 21:22:49 · 160 阅读 · 0 评论 -
LeetCode--Clone Graph
Clone Graph1. 题目Given the head of agraph, return a deep copy (clone) of the graph. Each node in the graph contains alabel(int) and a list (List[UndirectedGraphNode]) of itsneighbors. There is ...原创 2018-09-23 20:03:36 · 170 阅读 · 0 评论 -
LeetCode--Median of Two Sorted Arrays
Median of Two Sorted Arrays题目There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m...原创 2018-09-10 16:32:39 · 151 阅读 · 0 评论 -
LeetCode--Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters题目Given a string, find the length of the longest substring without repeating characters.ExampleInput: "abcabcbb"Output: 3 Explanation: The ans...原创 2018-09-10 10:56:08 · 127 阅读 · 0 评论 -
算法设计与分析第一周练习
题目 Given n non-negative integers a1, a2, …, an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find t...原创 2018-09-07 00:01:37 · 185 阅读 · 0 评论 -
LeetCode--Reverse Integer
Reverse Integer题目Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21No...原创 2018-09-16 23:39:02 · 154 阅读 · 0 评论