摘要: package main import "fmt" var swapcnt int func main() { arr := []int{2, 3, 4, 5, 1} //idx := Swap(arr, 0, len(arr)) //fmt.Println(idx, arr) myquickSor 阅读全文
posted @ 2022-08-31 13:14 Notomato 阅读(43) 评论(0) 推荐(0) 编辑
摘要: 二分图最大匹配数量,匈牙利算法求解 python,本质上是找增广回路 """ # File : hungary.py # Time :2022/8/28 21:08 # Author :notomato # Description: # """ ''' ''' # 六个点 # 第i个坐标存他相邻的点 阅读全文
posted @ 2022-08-29 12:55 Notomato 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 思路: 先转逆波兰,再求值 逆波兰求值的思路是,碰到数字入栈,碰到运算符则取栈顶两元素运算后入栈,最终栈内数字即为答案。 中缀表达式转为后缀表达式,即逆波兰表达式方法:对于中缀表达式的每个元素,遇到数字则直接加到结果上面,遇到操作符,若栈空或者当前操作符不小于栈顶操作符优先级(乘除大于加减),则入栈 阅读全文
posted @ 2022-08-27 19:01 Notomato 阅读(102) 评论(0) 推荐(0) 编辑
摘要: Python版本 class Trie: def __init__(self): self.children = defaultdict(Trie) self.word = "" self.is_word = False def insert(self, word): cur = self for 阅读全文
posted @ 2022-08-20 17:10 Notomato 阅读(26) 评论(0) 推荐(0) 编辑
摘要: Python版本 class UF: parent = {} size = {} cnt = 0 def __init__(self, M): # 初始化 parent,size 和 cnt # self.parent = {i for i in range(n)} def find(self, x 阅读全文
posted @ 2022-08-20 17:08 Notomato 阅读(5) 评论(0) 推荐(0) 编辑
摘要: n个活动,有起始时间和价值,时间不冲突的情况下的最大价值和对应的策略, package main import ( "fmt" "sort" "strconv" "strings" ) func main() { arr := [][]int{ {1, 4, 5}, {3, 5, 1}, {0, 6 阅读全文
posted @ 2022-08-16 20:34 Notomato 阅读(77) 评论(0) 推荐(0) 编辑
摘要: 根据先序中序->后序,先序后序->中序,中序后序->先序,构建二叉树的方法,注意根据先序后序构建中序并不是唯一的,下面的代码以字符串模拟,若要还原树结构,将关键部分换成node即可 package main import "fmt" func prein2post(preorder string, 阅读全文
posted @ 2022-08-15 15:11 Notomato 阅读(47) 评论(0) 推荐(0) 编辑
摘要: 邮局村庄问题,n个村庄m个邮局,每个村庄都要去一个离自己最近的邮局,求村庄到邮局的最短总距离 输入 n,m village 输出 最短距离 该问题是区间dp,首先假设只有一个邮局,则将邮局放在村庄数量的中位数位置可以得到最短距离, 设dis[i][j] 表示第i到j个村庄之间放一个邮局的最短距离,通 阅读全文
posted @ 2022-08-03 19:39 Notomato 阅读(83) 评论(0) 推荐(0) 编辑
摘要: 题目:求小于n的所有质数 package main import "fmt" func main() { primes := []int{} n := 1010 notprime := make(map[int]bool) for i := 2; i <= n; i++ { if !notprime 阅读全文
posted @ 2022-07-16 16:59 Notomato 阅读(62) 评论(0) 推荐(0) 编辑
摘要: 二进制转换 package main import ( "fmt" "strconv" ) func main() { // 10 进制转换为其他进制字符串 n := 123 fmt.Println(strconv.FormatInt(int64(n), 2)) // 1111011 // 输出二进 阅读全文
posted @ 2022-07-14 22:54 Notomato 阅读(507) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示