05 2021 档案
c++中map用法(以整数分解为例)
摘要:#include <map>#include <iostream>using namespace std; map<int, int> prime_factor(int n){ map<int, int> res; for(int i = 2; i * i <= n; ++i){ while(n % 阅读全文
posted @ 2021-05-22 16:24 城市里的月光 阅读(238) 评论(0) 推荐(0)
整数分解-利用python字典实现
摘要:def divisor(n): #建立一个空字典 dic = {} i = 2 while i * i <= n: while n % i == 0: #判断i是不是dic的一个键,如果是则遍历字典,把键为i的值更新 if i in dic: dic[i] = dic[i] + 1 #不是dic的一 阅读全文
posted @ 2021-05-13 17:20 城市里的月光 阅读(214) 评论(0) 推荐(0)
Python中创建树
摘要:class Node: #构造函数,内置了data参数 def __init__(self, data=""): self.data = data #左右孩子都为None self.lc = None self.rc = None #前序遍历 def pre_order(a): if(a): pri 阅读全文
posted @ 2021-05-06 19:37 城市里的月光 阅读(548) 评论(0) 推荐(0)