当前位置: 首页 > news >正文

wordpress安装分享插件下载微博搜索引擎优化

wordpress安装分享插件下载,微博搜索引擎优化,外资做网站的公司,网站建设市场行情分析路径压缩继续优化并查集 在实现的并查集中#xff0c;在合并操作merge(item1, item2)时#xff0c;会不管两个元素所在的分组大小#xff0c;总是将item 1的分组合并到item2的分组#xff0c;这样可能会导致树的深度无必要地增加#xff1a; 如果是大树合并到小树上在合并操作merge(item1, item2)时会不管两个元素所在的分组大小总是将item 1的分组合并到item2的分组这样可能会导致树的深度无必要地增加 如果是大树合并到小树上会导致树的深度增加进而造成增删改查等操作的代价增大 因此我们要对并查集的合并操作进行优化。 优化合并方式 每次合并时都将小分组的元素往大分组合并由于本例初始化都是一个元素对应一个分组它合并的情况可能会变成如下这样箭头代表分组之间的edge类似一颗星状的树 属性和方法说明 self.num_groups 分组数量self.groups 一个数组索引代表传入的item的值元素代表分组编号nums_in_each_group 一个数组索引代表分组编号元素代表每个分组的元素个数count_groups() 获取当前总共分数的数量in_the_same_group(item1, item2) 判断两个传入的item是否在同一分组which_group(item) 获取传入的item的所在分组unite(item1, item2) 合并两个元素到同一分组小的分组总是会往大的分组合并 Python代码实现及测试 class UF_Tree_Weighted:def __init__(self, n):self.num_groups nself.groups [i for i in range(n)]self.nums_in_each_group [1 for _ in range(n)]def count_groups(self):return self.num_groupsdef in_the_same_group(self, item1, item2):return self.which_group(item1) self.which_group(item2)def which_group(self, item):Find items root------groups[groups[groups[...groups[item]...]]]while self.groups[item] ! item:item self.groups[item]return itemdef unite(self, item1, item2):p self.which_group(item1)q self.which_group(item2)if p q:returnif self.nums_in_each_group[p] self.nums_in_each_group[q]:# Merge the smaller group into the biggersself.nums_in_each_group[q] self.nums_in_each_group[p]self.nums_in_each_group[p] 0# Change the smaller group-number to the biggers group-numberself.groups[p] self.groups[q]else:# Merge the smaller group into the biggersself.nums_in_each_group[p] self.nums_in_each_group[q]self.nums_in_each_group[q] 0self.groups[q] self.groups[p]# Numbers of group subtract 1self.num_groups - 1if __name__ __main__:UF UF_Tree_Weighted(5)print(fThe initial number of groups is {UF.num_groups})while True:p int(input(fInput the to-be-merge element: ))q int(input(fMerge to the target elements group: ))if UF.in_the_same_group(p, q):print(fThey are already in the same group)continueUF.unite(p, q)print(fThe number of groups now is {UF.count_groups()})print(UF.groups)print(fElements in each group: {UF.nums_in_each_group})运行结果 The initial number of groups is 5 Input the to-be-merge element: 0 Merge to the target elements group: 1 The number of groups now is 4 [1, 1, 2, 3, 4] Elements in each group: [0, 2, 1, 1, 1] Input the to-be-merge element: 1 Merge to the target elements group: 2 The number of groups now is 3 [1, 1, 1, 3, 4] Elements in each group: [0, 3, 0, 1, 1] Input the to-be-merge element: 3 Merge to the target elements group: 2 The number of groups now is 2 [1, 1, 1, 1, 4] Elements in each group: [0, 4, 0, 0, 1] Input the to-be-merge element: 2 Merge to the target elements group: 4 The number of groups now is 1 [1, 1, 1, 1, 1] Elements in each group: [0, 5, 0, 0, 0] Input the to-be-merge element: 当调用unite()合并时合并时不考虑参数的先后位置而是考虑分组的大小总是会有小的分组合并到大的分组
http://wiki.neutronadmin.com/news/415373/

相关文章:

  • 查看网站开发商工业设计公司宣传语
  • 宿迁宿豫网站建设视频制作表情包
  • 如何分析网站竞争对手徐州领航装饰工程有限公司
  • 百度电脑版登录网站冯耀宗seo课程
  • 苏州建网站用路由器建设网站
  • 建立自己的网站费用长沙百度百科
  • 校园网网站建设黑龙江网站建设
  • 上海免费网站建设模板推荐判断网站的好坏
  • 装饰公司怎么做网站河南建达工程建设监理公司网站
  • 顺德网站开发网站建设规划面试技巧
  • 永城城乡建设局网站网站怎么做镜像
  • 电商网站设计系统阳江市新增确诊病例
  • 桂林北站防疫电话营销网站的建设流程
  • 昆山网站建设书生商友二级网站怎么建
  • 英文网站域名注册刚做的网站为什么搜索不到
  • 钓鱼转转网站在线生成软件东莞做一个企业网站
  • 青岛公司建设网站移动惠生活app下载网址
  • 大同网站建设熊掌号wordpress腾讯cos
  • 网站开发 上海wordpress可以自动采集吗
  • 有用cc域名做网站的福建网站开发公司电话
  • 怎么引导做淘宝的客户做官方网站网站架构师工资
  • Wordpress在中国建站网站精美排版代码
  • 重庆建设工程信息网官网中苏业盛网站怎样做优化调整
  • 网站在哪里找广元网站设计
  • 网站建设支出账务处理flash在线制作网站
  • 网站编辑知识开发微信公众号需要多少钱
  • 设计网站如何推广企业网站脚本语言
  • 如何建设一个专业的网站公司域名备案全部过程
  • 网站建设的用途是什么意思网页设计实训总结心得体会
  • 广州优秀网站设计瑞安网站建设优化推广