python
文章平均质量分 69
automan_huyaoge
对智能机器人,无人驾驶感兴趣
展开
-
手势识别python
手势识别,准确率比较高原创 2023-05-22 10:31:38 · 807 阅读 · 0 评论 -
无监督学习python实现
1 -K-means Algorithmfrom sklearn import clusterimport pandas as pdimport numpy as npdataset = pd.DataFrame({ 'x': [11, 11, 20, 12, 16, 33, 24, 14, 45, 52, 51, 52, 55, 53, 55, 61, 62, 70, 72, 10], 'y': [39, 36, 30, 52, 53, 46, 55, 59, 12, 15,转载 2022-01-21 15:14:03 · 273 阅读 · 0 评论 -
python dfs和bfs
def bfs(graph, start): visited = [] queue = [start] while queue: node = queue.pop(0) if node not in visited: visited.append(node) neighbours = graph[node] for neighbour in neighbours: .转载 2022-01-21 10:56:00 · 162 阅读 · 0 评论 -
python线性规划
import pulpmodel = pulp.LpProblem("Profit_maximising_problem", pulp.LpMaximize)A = pulp.LpVariable('A', lowBound=0, cat='Integer')B = pulp.LpVariable('B', lowBound=0, cat='Integer')# Objective functionmodel += 5000 * A + 2500 * B, "Profit"# Constr.转载 2022-01-21 10:11:10 · 979 阅读 · 0 评论 -
查找算法python实现
Linear Searchdef LinearSearch(list, item): index = 0 found = False# Match the value with each data element while index < len(list) and found is False: if list[index] == item: found = True else:转载 2022-01-21 09:43:00 · 91 阅读 · 0 评论 -
排序算法python实现
Selection Sortdef SelectionSort(list): for fill_slot in range(len(list) - 1, 0, -1): max_index = 0 for location in range(1, fill_slot + 1): if list[location] > list[max_index]: max_index = location .转载 2022-01-20 11:11:02 · 78 阅读 · 0 评论 -
Algorithmic Heights第35题:Shortest Paths in DAG
ProblemThere are two subclasses of graphs that automatically exclude the possibility of negative cycles: graphs without negative edges, and graphs without cycles. We already know how to efficiently handle the former (see the problem“Negative Weight Cycl.转载 2021-01-26 09:36:02 · 170 阅读 · 0 评论 -
Algorithmic Heights第34题:Semi-Connected Graph
ProblemA directed graph issemi-connectedif for all pairs of verticesthere is either a path fromtoor a path fromto.Given:A positive integerandsimple directed graphswith at mostvertices each in theedge list format.Return:For each g...转载 2021-01-26 09:34:56 · 155 阅读 · 0 评论 -
Algorithmic Heights第33题:General Sink
ProblemGiven:A positive integerandsimple directed graphswith at mostvertices andedges each in theedge list format.Return:For each graph, output a vertex from which all other vertices are reachable (if such a vertex exists) and "-1" otherwis...转载 2021-01-25 09:50:05 · 108 阅读 · 0 评论 -
Algorithmic Heights第32题:2-Satisfiability
ProblemIn the 2SAT problem, you are given a set ofclauses, where each clause is the disjunction (OR) of two literals (a literal is a Boolean variable or the negation of a Boolean variable). You are looking for a way to assign a valueorto each of the...转载 2021-01-25 09:48:58 · 444 阅读 · 0 评论 -
Algorithmic Heights第31题:Strongly Connected Components
ProblemGiven:Asimple directed graphwithvertices in theedge list format.Return:The number ofstrongly connected componentsin the graph.鉴于:一个简单的向图与边列表格式的顶点。返回值:图形中强连接的组件数。Sample Dataset6 74 11 22 45 63 25 33 5Sample Output3...转载 2021-01-25 09:47:00 · 184 阅读 · 0 评论 -
Algorithmic Heights第30题:Quick Sort
ProblemComparing the algorithms forsortingand“Median”finding we notice that, beyond the commondivide-and-conquerphilosophy and structure, they are exact opposites.“Merge Sort”splits the array in two in the most convenient way (first half, second ...转载 2021-01-25 09:41:35 · 93 阅读 · 0 评论 -
Algorithmic Heights第29题:Negative Weight Cycle
ProblemThe task is to useBellman-Ford algorithmto check whether a given graph contains a cycle of negative weight.Given:A positive integerandsimple directed graphswith integer edge weights fromtoandvertices in theedge list format.Retur...转载 2021-01-25 09:40:25 · 177 阅读 · 0 评论 -
Algorithmic Heights第28题:Hamiltonian Path in DAG
ProblemA Hamiltonian path is a path in a graph that visits each vertex exactly once. Checking whether a graph contains a Hamiltonian path is a well-known hard problem. At the same time it is easy to perform such a check if a given graph is aDAG.Given:.转载 2021-01-25 09:39:00 · 184 阅读 · 0 评论 -
Algorithmic Heights第27题:Topological Sorting
ProblemGiven:Asimple directed acyclic graphwithvertices in theedge list format.Return:Atopological sorting(i.e., a permutation of vertices) of the graph.鉴于:一个简单的向无环图与边列表格式的顶点。返回:图的拓扑排序(即,顶点的排列)。Sample Dataset4 51 23 13 24 34 2...转载 2021-01-25 09:37:47 · 78 阅读 · 0 评论 -
Algorithmic Heights第26题:Partial Sort
ProblemGiven:A positive integerand an arrayof integers fromto, a positive integer.Return:Thesmallest elements of a sorted array.给定:正整数和一个数组来自的整数至,一个正整数。返回:该排序数组的最小元素。Sample Dataset104 -6 7 8 -9 100 12 13 56 173Sample...转载 2021-01-25 09:36:09 · 82 阅读 · 0 评论 -
Algorithmic Heights第25题:Median
ProblemThe task is to implement a linear time randomized algorithm for theselectionproblem.Given:A positive integerand an arrayof integers fromto, a positive number.Return:The-th smallest element of.Source:Algorithms by Dasgupta, Pap...转载 2021-01-25 09:34:16 · 107 阅读 · 0 评论 -
Algorithmic Heights第24题:Shortest Cycle Through a Given Edg
ProblemGiven:A positive integerandsimple directed graphswith positive integer edge weights and at mostvertices in theedge list format.Return:For each graph, output the length of a shortest cycle going through the first specified edge if there...转载 2021-01-25 09:32:44 · 95 阅读 · 0 评论 -
Algorithmic Heights第23题:Bellman-Ford Algorithm
ProblemFigure 1.The graph from the datasetThe task is to useBellman-Ford algorithmto compute single-source shortest distances in a directed graph with possibly negative edge weights (but without negative cycles).Given:Asimple directed graphwi...转载 2021-01-23 20:28:04 · 103 阅读 · 0 评论 -
Algorithmic Heights第22题:Square in a Graph
ProblemGiven:A positive integerandsimple undirected graphswithvertices in theedge list format.Return:For each graph, output "1" if it contains a simple cycle (that is, a cycle which doesn’t intersect itself) of lengthand "-1" otherwise.So...转载 2021-01-23 20:25:18 · 103 阅读 · 0 评论 -
Algorithmic Heights第21题:3-Way Partition
ProblemThis problem is very similar to“2-Way Partition”, but now the goal is to partition an input array more carefully.Given:A positive integerand an arrayof integers fromto.Return:An arraysuch that it is a permutation ofand there ar...转载 2021-01-23 20:22:52 · 106 阅读 · 0 评论 -
Algorithmic Heights第20题:Counting Inversions
ProblemAn inversion of an arrayis a pair of indicessuch thatand. The number of inversions shows how far the array is from being sorted: if it is already sorted then there are no inversions, whereas if it is sorted in reverse order then the number ...转载 2021-01-23 20:16:46 · 163 阅读 · 0 评论 -
Algorithmic Heights第19题:Heap Sort
ProblemThe heap sort algorithm first transforms a given array into amax heap(recall the problem“Building a Heap”). It then repeats the following two simple stepstimes:Swap the last element of the heap with its root and decrease the size of the hea...转载 2021-01-23 20:15:21 · 100 阅读 · 0 评论 -
Algorithmic Heights第18题:Dijkstra‘s Algorithm
ProblemFigure 1.The graph from the dataset图1。数据集中的图形The task is to useDijkstra's algorithmto compute single-source shortest distances in a directed graph with positive edge weights.Given:Asimple directed graphwith positive edge weights fro...转载 2021-01-23 20:13:13 · 150 阅读 · 0 评论 -
Algorithmic Heights第17题:Testing Acyclicity
ProblemFigure 1.The graphs from the dataset图1。数据集中的图形Given:A positive integerandsimple directed graphsin theedge list formatwith at mostvertices andedges each.Return:For each graph, output "1" if the graph isacyclicand "-1" other...转载 2021-01-23 20:10:25 · 81 阅读 · 0 评论 -
Algorithmic Heights第16题:Testing Bipartiteness
ProblemFigure 1.The graphs from the dataset图1。数据集中的图形Abipartitegraph is a graphwhose vertices can be partitioned into two sets (and) such that there are no edges between vertices in the same set (for instance, if, then there is no edge bet...转载 2021-01-23 20:08:13 · 267 阅读 · 0 评论 -
Algorithmic Heights第15题:3SUM
ProblemGiven:A positive integer, a postive integer, andarrays of sizecontaining integers fromto.Return:For each array, output three different indicessuch thatif exist, and "-1" otherwise.问题给定:正整数,一个正整数和大小数组包含来自至。返回:对于每个数组,...转载 2021-01-23 20:05:12 · 101 阅读 · 0 评论 -
Algorithmic Heights第14题:2-Way Partition
ProblemA partition procedure is an essential part of the Quick Sort algorithm, the subject of one of the following problems. Its main goal is to put the first element of a given array to its proper place in a sorted array. It can be implemented inlinear.转载 2021-01-23 20:03:37 · 94 阅读 · 0 评论 -
Algorithmic Heights第13题:Merge Sort
ProblemThe problem ofsortinga list of numbers lends itself immediately to adivide-and-conquerstrategy: split the list into two halves, recursively sort each half, and then merge the two sorted sublists (recall the problem“Merge Two Sorted Arrays”)....转载 2021-01-22 20:18:45 · 105 阅读 · 0 评论 -
Algorithmic Heights第12题:Building a Heap
ProblemAbinary heapis abinary treebased data structure that is often used to implementpriority queues. Binary heaps, in turn, can be easily implemented using an array if the underlying tree is a complete binary tree. The tree nodes have a natural or...转载 2021-01-22 20:13:20 · 115 阅读 · 0 评论 -
Algorithmic Heights第11题:Connected Components
ProblemFigure 1.The graph from the dataset图1。数据集中的图形The task is to usedepth-first searchto compute the number ofconnected componentsin a given undirected graph.Given:Asimple graphwithvertices in theedge list format.Return:The numbe...转载 2021-01-22 20:12:04 · 107 阅读 · 0 评论 -
Algorithmic Heights第10题:Breadth-First Search
ProblemFigure 1.The graph from the dataset图1。数据集中的图形The task is to usebreadth-first searchto compute single-source shortest distances in an unweighted directed graph.Given:Asimple directed graphwithvertices in theedge list format.Retu...转载 2021-01-22 20:10:44 · 130 阅读 · 0 评论 -
Algorithmic Heights第9题:2SUM
ProblemGiven:A positive integer, a positive integer, andarrays of sizecontaining integers fromto.Return:For each array, output two different indicessuch thatif exist, and "-1" otherwise.给定:正整数,一个正整数和大小数组包含来自至。返回:对于每个数组,输出两个不...转载 2021-01-22 20:07:12 · 93 阅读 · 0 评论 -
Algorithmic Heights第8题:Merge Two Sorted Arrays
ProblemThe merging procedure is an essential part of“Merge Sort”(which is considered in one of the next problems).Given:A positive integerand a sorted arrayof integers fromto, a positive integerand a sorted arrayof integers fromto.Re...转载 2021-01-22 20:04:38 · 106 阅读 · 0 评论 -
Algorithmic Heights第7题:Merge Two Sorted Arrays
ProblemThe merging procedure is an essential part of“Merge Sort”(which is considered in one of the next problems).Given:A positive integerand a sorted arrayof integers fromto, a positive integerand a sorted arrayof integers fromto.Re...转载 2021-01-22 19:50:06 · 166 阅读 · 0 评论 -
Algorithmic Heights第6题:Majority Element
ProblemAn arrayis said to have amajority elementif more than half of its entries are the same.Given:A positive integer, a positive integer, andarrays of sizecontaining positive integers not exceeding.Return:For each array, output an elem...转载 2021-01-22 19:47:47 · 162 阅读 · 1 评论 -
Algorithmic Heights第5题:Double-Degree Array
ProblemFigure 1.The graph from the dataset图1。数据集中的图形Source:Algorithms by Dasgupta, Papadimitriou, Vazirani. McGraw-Hill. 2006.Given:Asimple graphwithvertices in theedge list format.Return:An arraywhereis the sum of the degrees of...转载 2021-01-22 19:46:27 · 134 阅读 · 0 评论 -
Algorithmic Heights第4题:Insertion Sort
Computing the number of swaps in insertion sortInsertion sort is a simple sorting algorithm that builds the final sorted array one item at a time. It is much less efficient on large lists than more advanced algorithms such as“Quick Sort”,“Heap Sort”, o..转载 2021-01-22 19:44:50 · 109 阅读 · 0 评论 -
Algorithmic Heights第3题:Degree Array
Why graphs?Figure 1Figure 2A wide range of problems can be expressed with clarity and precision in the concise pictorial language ofgraphs. For instance, consider the task of coloring a political map. What is the minimum number of colors needed,.转载 2021-01-21 11:05:20 · 171 阅读 · 0 评论 -
Algorithmic Heights第2题:Binary Search
Binary search is the ultimatedivide-and-conqueralgorithm. To find a keyin a large file containing keysin sorted order, we first comparewith, and depending on the result we recurse either on the first half of the file,, or on the second half,. Th...转载 2021-01-21 11:03:09 · 127 阅读 · 0 评论