4 Zetrue_Li



One of juniors in Sun Yat-sen University

TA的排名 10w+

Python plotTree.py —— 决策树绘图模块函数

Python plotTree.py —— 决策树绘图模块函数保存以下代码为plotTree.py,在所需调用的py文件,加入代码:import plotTreeplotTree.createPlot(Tree)plotTree.py:import matplotlib.pyplot as pltfrom pylab import *# 定义文本框和箭头格式d...

2019-03-26 15:41:45

Solve TSP with dynamic programming——动态规划解决旅行商(邮递员)问题

无向简单图的TSP算法小规模精确解:算法思想:小规模精确解的算法中心思想是动态规划思想。假设给定顶点集合V为{0,1,2,3,4,... .n}。由于图为无向完全图,我们可以很自然地将0视为输出的起点和终点。对于每个其他顶点i(除0之外),我们找到以0为起点,i为终点,且所有顶点恰好出现一次的最小成本路径。假设定义这条最小成本路径的成本为Cost(i),则相应TSP回路的Cost将...

2018-12-10 11:13:21


玩家模块的规范:用一个长度为2的字符串表示一张牌:(D,C,H,S) + (A,2,3,4,5,6,7,8,9,0,J,Q,K) 用"jk"、"JK"分别表示小王、大王游戏顺序是逆时针方向角色用一个字符串表示,("banker","banker_opposite","banker_left","banker_right")分别表示庄家、庄家的对家、庄家的左边、庄家的右边不考虑甩牌...

2018-12-10 10:54:00

Futoshiki solving wih GAC using Python

代码实现:import timeimport queuesize = 0 def read(string): global size board = [] small, large = {}, {} with open(string) as f: line = f.readline() size = int(line) for _ in range(size...

2018-10-28 21:52:39

IDA* 迭代加深A star算法解决15数码问题——python实现

 1 IDA* Algorithm1.1 DescriptionIterative deepening A* (IDA*) was first described by Richard Korf in 1985, which is a graph traversaland path search algorithm that can find the shortest path bet...

2018-09-14 14:42:21


个人原创,禁止转载——Zetrue_Li  问题描述:在一个序列里找出第K小元素以下程序基于函数 int select_kth_smallest(list q, int k) 实现 :返回向量q中第k最小元的函数算法一:基于冒泡排序思想,暴力求解:基本思路:要求找出第k个最小元素,可以通过在序列中遍历k次,每次找出最小的,并放在序列头。类似泡泡一样,找出第k个大的泡泡(bu...

2018-09-12 19:23:25

LeetCode 561. Array Partition I——python一行代码解决

问题来源:561. Array Partition I问题描述:Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) fo...

2018-08-24 23:28:28

LeetCode 867. Transpose Matrix——python一行代码解决

问题来源:867. Transpose Matrix问题描述:Given a matrix A, return the transpose of A.The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the ma...

2018-08-24 23:17:11

LeetCode 832. Flipping an Image——python一行代码解决

问题来源:832. Flipping an Image问题描述:Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image.To flip an image horizontally means that each row ...

2018-08-24 14:33:15

LeetCode 728. Self Dividing Numbers——python一行代码解决

问题来源 728. Self Dividing Numbers问题描述:A self-dividing number is a number that is divisible by every digit it contains.For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0,...

2018-08-24 14:29:55

Exercise: Sklearn

Steps1 Create a classification dataset (n samples 1000, n features 10)2 Split the dataset using 10-fold cross validation3 Train the algorithmsI GaussianNBI SVC (possible C values [1e-02, 1e-01, 1e00...

2018-06-18 21:37:52

Exercise: Jupyter

 Exercise: JupyterPart 1For each of the four datasets...Compute the mean and variance of both x and yCompute the correlation coefficient between x and yCompute the linear regression line: y=β0+β1x+ϵy=...

2018-06-12 16:33:30

Exercise: Scipy

Exercise 10.1: Least squaresGenerate matrix A ∈ Rm × n with m > n. Also generate some vector b ∈ Rm.Now find x = argminx k Ax − bk 2.Print the norm of the residual.残差定义:scipy.optimize.lsq_linearsci...

2018-06-05 14:22:59

Exercise: Matpotlib

Exercise 11.1: Plotting a function    Plot the function           over the interval [0, 2]. Add proper axis labels, a title, etc.numpy.expnumpy.exp(x, /, out=None, *, where=True, casting='same_kind', ...

2018-05-29 09:06:50

Exercise: Numpy

Exercise: NumpyGenerate matrices A, with random Gaussian entries, B, a Toeplitz matrix, where A ∈Rn × m and B ∈Rm × m, for n = 200, m = 500.构造A:利用内置函数numpy.random. normal(loc=0.0, scale=1.0, size=None...

2018-05-19 16:24:28

LeetCode 71. Simplify Path

一、       问题描述:Given an absolute path for a file(Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:·        Did you consider the case w...

2018-05-16 19:15:08

LeetCode 6. ZigZag Conversion

一、     问题描述:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows likethis: (you may want to display this pattern in a fixed font for betterlegibility)P   A   H   NA P L...

2018-05-05 22:10:54

LeetCode 5. Longest Palindromic Substring

一、       问题描述:Given a string s, find the longestpalindromic substring in s. You may assumethat the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.E...

2018-04-28 17:35:04

LeetCode 49. Group Anagrams

一、     问题描述:Given an array of strings, groupanagrams together.Example:Input:["eat", "tea", "tan","ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat",&

2018-04-27 22:27:53

LeetCode 11. Container With Most Water

一、问题描述:    Given n non-negativeintegers a1, a2, ..., an, where each represents a point atcoordinate (i, ai). n verticallines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). F...

2018-04-25 20:09:30


勋章 我的勋章
  • 勤写标兵Lv2