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

网站首页设置伪静态/网络营销的成功案例有哪些

网站首页设置伪静态,网络营销的成功案例有哪些,网站建设营销口号,河北邢台人品怎么样最小生成树算法prime的具体算法这里不再赘述,很多地方都有介绍,下面着重介绍采用最小堆实现的基本原理。 使用最小堆时需要几个数据结构: 1> Index表,用来查找每个节点在堆中的具体位置 2> Node{int pos , int val}; 堆中…

最小生成树算法prime的具体算法这里不再赘述,很多地方都有介绍,下面着重介绍采用最小堆实现的基本原理。


使用最小堆时需要几个数据结构:

1> Index表,用来查找每个节点在堆中的具体位置

2> Node{int pos , int val}; 堆中的节点

pos,用来记录该节点在index表中的位置

val , 表示该节点与已经拓展的节点的最小距离,该结点需要时时改变。

3> del表,记录该元素是否已经拓展


需要用的几个方法:

keepHeap(int pos):

用来保持堆的性质,当删除堆顶时,需要交换最后一个元素到堆顶,然后从上向下保持堆。

adjustHeap(int pos , int val):

将堆中pos处的节点val变为为val,在本例中,val是比堆中已经存在元素小,因此只需要向上拓展堆。


算法流程如下:

1》 初始化堆:

void initHeap()
{
Heap[0].pos = 0;
Heap[0].val = 0;
Index[0] = 0;
HeapSize = N;
for (int i = 1; i < N; ++i)
{
Heap[i].val = INITMAX;
Heap[i].pos = i;
Index[i] = i;
}
memset(del , 0 , sizeof(del));
}


2>当heapsize != 0时, //第一层循环

弹出堆顶元素node. ,设该节点为u , (由于此步将顶部元素给删除了,因此需要keepHeap, 且del[u] = true)

对与node相邻的所有结点v //第二层循环

如果v还没拓展,且节点v在Heap中的val值小于 d(u , v) , 则需要修改堆中节点v的值为d(u,v), 这时需要adjustHeap(vpos , d(u,v));

将heapsize --; 继续循环。

del[u] = true,说明u已经被拓展。


由2可知,该算法的时间繁杂度为O(E * Log(N)); , 这是因为在第二循环遍历到了每个边,且调用addjustHeap时时间复杂度为log(N)。


下面是一个针对一个问题的实现 :

问题如下:

Description
The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that it will be possible to drive between any pair of towns without leaving the highway system.

Flatopian towns are numbered from 1 to N. Each highway connects exactly two towns. All highways follow straight lines. All highways can be used in both directions. Highways can freely cross each other, but a driver can only switch between highways at a town that is located at the end of both highways.

The Flatopian government wants to minimize the length of the longest highway to be built. However, they want to guarantee that every town is highway-reachable from every other town.
Input
The first line is an integer N (3 <= N <= 500), which is the number of villages. Then come N lines, the i-th of which contains N integers, and the j-th of these N integers is the distance (the distance should be an integer within [1, 65536]) between village i and village j.
Output
You should output a line contains an integer, which is the length of the longest road to be built such that all the villages are connected, and this value is minimum.
This problem contains multiple test cases!
The first line of a multiple input is an integer T, then a blank line followed by T input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of T output blocks. There is a blank line between output blocks.
Sample Input
Copy sample input to clipboard
13
0 990 692
990 0 179
692 179 0
Sample Output
692



#include <iostream> #include <stdio.h> #include <string.h> using namespace std; const int INITMAX = 9999999; const int NMAX = 501; int T , N; int Table[NMAX][NMAX]; struct Node { int pos ; int val; }; int HeapSize ; Node Heap[NMAX]; int Index[NMAX]; bool del[NMAX]; void input() { scanf("%d" , &N); for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { scanf("%d" , &Table[i][j]); } } } void initHeap() { Heap[0].pos = 0; Heap[0].val = 0; Index[0] = 0; HeapSize = N; for (int i = 1; i < N; ++i) { Heap[i].val = INITMAX; Heap[i].pos = i; Index[i] = i; } memset(del , 0 , sizeof(del)); } void keepHeap(int pos) { int l = (pos << 1) + 1; int r = l + 1; int tp = pos; if (l < HeapSize && Heap[l].val < Heap[tp].val) { tp = l; } if (r < HeapSize && Heap[r].val < Heap[tp].val) { tp = r; } if (tp != pos) { Index[Heap[pos].pos] = tp; Index[Heap[tp].pos] = pos; std::swap(Heap[pos] , Heap[tp]); keepHeap(tp); } } void adjustHeap(int pos , int val) { Heap[pos].val = val; while (pos > 0) { int tp = (pos - 1) >> 1; if (Heap[tp].val > Heap[pos].val) { Index[Heap[tp].pos] = pos; Index[Heap[pos].pos] = tp; std::swap(Heap[tp] , Heap[pos]); pos = tp; } else { break; } } } Node popHeap() { Node top = Heap[0]; del[top.pos] = true; Heap[0] = Heap[HeapSize - 1]; Index[Heap[0].pos] = 0; keepHeap(0); HeapSize--; return top; } int prime() { initHeap(); int Max = 0; while (HeapSize > 0) { Node node = popHeap(); if (node.val > Max) { Max = node.val; } int i = node.pos; for (int j = 0; j < N; ++j) { if (i == j || del[j]) { continue; } int tval = Heap[Index[j]].val; if (Table[i][j] < tval) { adjustHeap(Index[j] , Table[i][j]); } } } return Max; } int main() { scanf("%d" , &T); while (T--) { input(); cout << prime()<<endl; if (T != 0) { cout <<endl; } } return 0; }




http://www.jmfq.cn/news/4961719.html

相关文章:

  • 网站建设 有限公司/自动外链发布工具
  • 杭州的电商网站建设/恢复正常百度
  • go做网站/怎么做产品推广和宣传
  • 网站的互动功能/360手机助手
  • 网站设计与网页制作招聘/长沙网站seo源头厂家
  • 自己做网站的难度/网络营销策划书包括哪些内容
  • wordpress站内计费搜索/百度关键词价格
  • 客服24小时在线服务/我赢seo
  • 潍坊做网站建设的公司/百度账户登录
  • 做编程的 网站/磁力搜索引擎哪个好
  • 网站运营工作/网站搭建源码
  • 管理网站用什么系统好/网络营销公司如何建立
  • 武汉网站建设电话多少钱/网络营销师培训
  • 有哪些好的网站制作公司/百度注册公司网站
  • 中国互联网协会会员单位/seo在线培训
  • 腊肉网站的建设前景/今日新闻头条最新消息
  • 可以接单做3d网站/个人seo怎么赚钱
  • ptp网站开发/网络营销和传统营销的关系
  • 做网站域名大概多少钱/三亚网络推广
  • 如何做外贸soho做网站/成人用品哪里进货好
  • 江苏海通建设有限公司网站/关键词排名点击软件首页
  • 网站建设 高端 北京/今日全国最新疫情通报
  • 郑州宣传片制作/朝阳seo推广
  • 网站icp备案管理系统/广点通和腾讯朋友圈广告区别
  • 医院网站站群建设/seo查询
  • c语言做项目网站/免费html网站制作成品
  • 网站开发者/百度图片查找
  • 杭州网站排名优化公司/抖音推广平台
  • 学校网站建设目的与意义/如何用网站模板建站
  • 仿网站ppt怎么做/百度热搜榜