- 博客(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
4563
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
273
原创 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
303
原创 LeetCode743. 网络延迟时间(Dijkstra算法)
LeetCode743. 网络延迟时间(Dijkstra算法)codeclass Solution: def networkDelayTime(self, times: list, N: int, K: int) -> int: inf = int(1e9) g = [[int(1e9)] * N for _ in range(N)] ...
2019-03-12 00:21:48
1282
原创 LeetCode279. 完全平方数(DP+四平方和)
LeetCode279. 完全平方数(DP+四平方和)转化为完全背包的DP问题from math import sqrtclass Solution: def numSquares(self, n: int) -&gt; int: ans = n maxn = int(sqrt(n)) dp = [_ for _ in range(...
2019-03-08 12:52:53
350
原创 LeetCode142. 环形链表 II(快慢指针)
快慢指针参考https://zhuanlan.zhihu.com/p/30990994?utm_source=qq&utm_medium=social&utm_oi=1080275092017270784# Definition for singly-linked list.class ListNode(object): def __init__(self, x):...
2019-03-06 23:45:18
186
原创 LeetCode141. 环形链表(快慢指针)
LeetCode141. 环形链表(快慢指针)快慢指针参考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): ...
2019-03-06 23:17:35
269
原创 LeetCode45. 跳跃游戏 II
LeetCode45. 跳跃游戏 IIclass Solution: def jump(self, nums): """ :type nums: List[int] :rtype: int """ cnt, s, e, far = 0, 0, 0, 0 while far &lt;
2019-03-04 20:40:41
146
原创 LeetCode135. 分发糖果
LeetCode135. 分发糖果画折线图理解class Solution: def candy(self, ratings: list) -> int: cnt = 1 tmp = 1 l = 1 r = 0 for i in range(1, len(ratings)): ...
2019-03-04 19:09:23
244
原创 LeetCode101. 对称二叉树 (递归) + (迭代)
LeetCode101. 对称二叉树 (递归) + (迭代)递归class Solution: def isSymmetric(self, root): """ :type root: TreeNode :rtype: bool """ if root: return sel...
2019-03-01 17:12:11
471
原创 LeetCode870. 优势洗牌(贪心算法) Python实现
LeetCode870. 优势洗牌(贪心算法)贪心策略: 田忌赛马codeclass Solution: def advantageCount(self, A: list, B: list) -&gt; list: l = len(A) ans = [0 for _ in range(l)] b = sorted(lis...
2019-03-01 14:10:21
499
原创 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
130
原创 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
499
原创 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
388
原创 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
165
原创 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
286
原创 LeetCode1 两数之和(字典法)
LeetCode1 两数之和(字典法)class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: m = {} for idx, x in enumerate(nums): y = target - x if ...
2019-02-25 21:57:18
259
原创 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
138
原创 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
1712
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
215
原创 LeetCode695 岛屿的最大面积(DFS)
LeetCode695 岛屿的最大面积(DFS)class Solution: def __init__(self): self.tmp = 0 def maxAreaOfIsland(self, grid: 'List[List[int]]') -> 'int': w = len(grid) h =len(grid[0]...
2019-02-25 17:31:05
292
原创 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
1635
原创 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
872
原创 使用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
7582
原创 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
610
原创 单向链表
单向链表相关函数代码整理笔记code#include&lt;iostream&gt;#include&lt;cstdlib&gt;using namespace std;typedef struct LNode{ int data; struct LNode *next;}LNode,*LinkList;void CreateLink(LinkLi...
2018-09-01 15:02:09
145
原创 顺序表操作
顺序表操作code存放在h头文件中,调用即可#include&lt;iostream&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
171
原创 欧拉筛法_求素数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
609
原创 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
2109
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人