自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(29)
  • 收藏
  • 关注

原创 Lingo非线性规划

max = 98 * x1 + 277 * x2 - x1 ^ 2 - 0.3 * x1 * x2 - 2 * x2 ^ 2;x1 + x2 <= 100;x1 <= 2 * x2;@gin(x1);@gin(x2);min = x1 ^2 + x2 ^ 2 + x3 ^ 2 + 8;x1 ^ 2 - x2 + x3 ^ 2 >= 0;x1 + x2 ^ 2...

2019-06-27 17:29:52 4130 1

原创 Dinic算法_网络最大流

Dinic算法_网络最大流Python versionclass Dinic: '''Dinic algorithm''' def __init__(self, V:int, E:int, graph:'List[List[int]]', S:int, T:int): self.n, self.m = V, E # V = |Vertices|, E = ...

2019-04-30 20:05:14 203

原创 LeetCode337. 打家劫舍 III(DFS记忆化搜索)

LeetCode337. 打家劫舍 III(DFS记忆化搜索)# Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = Noneclass Solution:...

2019-03-24 18:55:40 240

原创 LeetCode743. 网络延迟时间(Dijkstra算法)

LeetCode743. 网络延迟时间(Dijkstra算法)codeclass Solution: def networkDelayTime(self, times: list, N: int, K: int) -&gt; int: inf = int(1e9) g = [[int(1e9)] * N for _ in range(N)] ...

2019-03-12 00:21:48 1175

原创 LeetCode279. 完全平方数(DP+四平方和)

LeetCode279. 完全平方数(DP+四平方和)转化为完全背包的DP问题from math import sqrtclass Solution: def numSquares(self, n: int) -&amp;gt; int: ans = n maxn = int(sqrt(n)) dp = [_ for _ in range(...

2019-03-08 12:52:53 294

原创 LeetCode142. 环形链表 II(快慢指针)

快慢指针参考https://zhuanlan.zhihu.com/p/30990994?utm_source=qq&amp;utm_medium=social&amp;utm_oi=1080275092017270784# Definition for singly-linked list.class ListNode(object): def __init__(self, x):...

2019-03-06 23:45:18 137

原创 LeetCode141. 环形链表(快慢指针)

LeetCode141. 环形链表(快慢指针)快慢指针参考https://zhuanlan.zhihu.com/p/30990994?utm_source=qq&amp;amp;utm_medium=social&amp;amp;utm_oi=1080275092017270784# Definition for singly-linked list.class ListNode(object): ...

2019-03-06 23:17:35 199

原创 LeetCode45. 跳跃游戏 II

LeetCode45. 跳跃游戏 IIclass Solution: def jump(self, nums): &quot;&quot;&quot; :type nums: List[int] :rtype: int &quot;&quot;&quot; cnt, s, e, far = 0, 0, 0, 0 while far &amp;lt;

2019-03-04 20:40:41 109

原创 LeetCode135. 分发糖果

LeetCode135. 分发糖果画折线图理解class Solution: def candy(self, ratings: list) -&gt; int: cnt = 1 tmp = 1 l = 1 r = 0 for i in range(1, len(ratings)): ...

2019-03-04 19:09:23 164

原创 LeetCode101. 对称二叉树 (递归) + (迭代)

LeetCode101. 对称二叉树 (递归) + (迭代)递归class Solution: def isSymmetric(self, root): """ :type root: TreeNode :rtype: bool """ if root: return sel...

2019-03-01 17:12:11 408

原创 LeetCode870. 优势洗牌(贪心算法) Python实现

LeetCode870. 优势洗牌(贪心算法)贪心策略: 田忌赛马codeclass Solution: def advantageCount(self, A: list, B: list) -&amp;gt; list: l = len(A) ans = [0 for _ in range(l)] b = sorted(lis...

2019-03-01 14:10:21 452

原创 LeetCode112.路径总和

LeetCode112.路径总和version 1# Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = Noneclass Solution: ...

2019-02-27 09:46:06 99

原创 LeetCode104.二叉树的最大深度 (BFS)+(递归)两种方法

LeetCode104.二叉树的最大深度 (BFS)+(递归)两种方法BFS# Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None ...

2019-02-26 15:52:07 465

原创 LeetCode111. 二叉树的最小深度 (BFS) + (递归)两种方法

LeetCode111. 二叉树的最小深度 (BFS) + (递归)两种方法BFS# Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None ...

2019-02-26 15:42:25 336

原创 LeetCode47. 全排列 II:(DFS) + (import itertools)

LeetCode47. 全排列 II:(DFS) + (import itertools)class Solution: def __init__(self): self.n = None self.v = None self.tmp = () self.tmp_ans = [] def permuteUnique...

2019-02-26 00:36:03 120

原创 LeetCode46. 全排列 两种方法:(DFS) + (import itertools)

LeetCode46. 全排列(DFS)class Solution: def __init__(self): self.v = None self.n = None self.tmp = [] self.ans = [] def permute(self, nums): self.n = len(...

2019-02-25 23:53:54 246

原创 LeetCode1 两数之和(字典法)

LeetCode1 两数之和(字典法)class Solution: def twoSum(self, nums: List[int], target: int) -&gt; List[int]: m = {} for idx, x in enumerate(nums): y = target - x if ...

2019-02-25 21:57:18 220

原创 LeetCode513 找树左下角的值(BFS)

LeetCode513 找树左下角的值(BFS)BFS算法层层遍历,记录每层的最左边的结点的值# Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = No...

2019-02-25 21:16:47 97

原创 Python实现二叉树(4种遍历,含层序遍历)

Python实现二叉树(4种遍历,含层序遍历)codeclass TreeNode(object): def __init__(self, data=None, left=None, right=None): self.data = data self.left = left self.right = rightclass Bi...

2019-02-25 20:39:37 1608 1

原创 LeetCode104 二叉树的最大深度(DFS)

LeetCode104 二叉树的最大深度(DFS)DFS递归# Definition for a binary tree node.class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = Noneclass Solutio...

2019-02-25 17:47:19 166

原创 LeetCode695 岛屿的最大面积(DFS)

LeetCode695 岛屿的最大面积(DFS)class Solution: def __init__(self): self.tmp = 0 def maxAreaOfIsland(self, grid: 'List[List[int]]') -&gt; 'int': w = len(grid) h =len(grid[0]...

2019-02-25 17:31:05 253

原创 Python 实现 账本bill GUI小项目(wxPython)

Python 实现 账本bill GUI小项目GUI采用wxPython使用txt文本进行记录和读取数据,按照日期进行快速排序,点击Plot按钮可打印账单并绘制图表实现可视化效果如下图import wximport matplotlib.pyplot as pltclass PocketTxt: def __init__(self, filename): ...

2019-02-20 18:02:58 1526

原创 Python 实现 遗传算法(GA)

Python 实现 遗传算法(GA)Python Code (GA)"""遗传算法实现求函数极大值"""#from numba import jitimport numpy as npimport matplotlib.pyplot as pltclass GA(): '''genetic algorithm''' def __init__(self,targ...

2019-02-18 17:02:10 779

原创 使用sklearn生成数据集

使用sklearn生成数据集sklearn.datasets 中有多个生成数据集的方法1.生成符合正态分布的聚类数据sklearn.datasets.make_blobs(n_samples=100, n_features=2, centers=3, cluster_std=1.0, center_box=(-10.0, 10.0), shuffle=True, rando...

2019-02-18 14:07:37 7372

原创 Python 实现二叉搜索树(Binary Search Tree) and c++实现

Python 实现二叉搜索树(Binary Search Tree)and c++实现Pythonimport numpy as npclass Node(object): def __init__(self, data= None, lchild=None, rchild=None, parent=None): self.key = data ...

2019-02-17 22:25:10 573

原创 单向链表

单向链表相关函数代码整理笔记code#include&amp;lt;iostream&amp;gt;#include&amp;lt;cstdlib&amp;gt;using namespace std;typedef struct LNode{ int data; struct LNode *next;}LNode,*LinkList;void CreateLink(LinkLi...

2018-09-01 15:02:09 110

原创 顺序表操作

顺序表操作code存放在h头文件中,调用即可#include&amp;lt;iostream&amp;gt;const int MAXSIZE=100;using namespace std;//定义顺序表结构typedef struct{ //define structure int *a; int len; int listsize;}List;void I...

2018-08-30 17:48:44 133

原创 欧拉筛法_求素数O(n)

欧拉筛法_求素数O(n)Theoretical basis:任何合数(combined number)都能表示成一系列素数(pirme number)的积。Because every combined number has its own maximal prime factor(let’s call it maxp),it’s better to screen prime numbers...

2018-08-24 21:03:57 527

原创 memset()

memset notememset函数原型为: void *memset(void *buffer,int c,int count)包含在sting.h(C)和cstring(C++)头文件中 buffer为数组或指针,c为赋给buffer的值,count是buffer的内存长度memset的操作对象是内存空间 memset函数通常为新分配的内存做初始化工作 且初始化赋值...

2018-08-17 01:54:47 2056

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除