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

扶余手机网站开发营销推广策划及渠道

扶余手机网站开发,营销推广策划及渠道,b2c网站开发,WordPress修改模板相对路径很明显聪明的同学已经发现,这是一个稠密图,所以用邻接矩阵。可以很好的表达,比邻接表有优势,所以,采用邻接矩阵破题, 当然也可以用邻接表,仔细观察我的AC,会发现其实都一样,只是存储…

很明显聪明的同学已经发现,这是一个稠密图,所以用邻接矩阵。可以很好的表达,比邻接表有优势,所以,采用邻接矩阵破题,

当然也可以用邻接表,仔细观察我的AC,会发现其实都一样,只是存储形式不一样罢了。

很明显,这是一个最小生成树问题,也可以认为贪心算法,接下来我将分别展示两个实现路径,第一个 prim 算法, 第二个kruskal算法。

 第一个 prim 算法,哈哈,原来是我最开始搞错方向了,并未理解prim算法,这下也是让我印象深刻了。

测试点提示内存(KB)用时(ms)结果得分
0sample换数字,各种回路判断1924

答案正确

15 / 15
1M<N-1,不可能有生成树1924

答案正确

2 / 2
2M达到N-1,但是图不连通1924

答案正确

2 / 2
3最大N和M,连通42848

答案正确

5 / 5
4最大N和M,不连通41607

答案正确

6 / 6

 第二个kruskal算法,实际应用很简单,果然馒头嚼碎也不见得好吸收,一点点啃食的过程,也是非常锻炼计算思维。

按道理来说,应该是kruskal算法快,但是也就一个O(N^2) 与O(NlogN),可以看出来在1000个数据点(最大N(1000),M(3000))下,区别还是有的。

测试点提示内存(KB)用时(ms)结果得分
0sample换数字,各种回路判断1884

答案正确

15 / 15
1M<N-1,不可能有生成树1884

答案正确

2 / 2
2M达到N-1,但是图不连通1884

答案正确

2 / 2
3最大N和M,连通41567

答案正确

5 / 5
4最大N和M,不连通41606

答案正确

6 / 6

现有村落间道路的统计数据表中,列出了有可能建设成标准公路的若干条道路的成本,求使每个村落都有公路连通所需要的最低成本。

输入格式:

输入数据包括城镇数目正整数 n(≤1000)和候选道路数目 m(≤3n);随后的 m 行对应 m 条道路,每行给出 3 个正整数,分别是该条道路直接连通的两个城镇的编号以及该道路改建的预算成本。为简单起见,城镇从 1 到 n 编号。

输出格式:

输出村村通需要的最低成本。如果输入数据不足以保证畅通,则输出 −1,表示需要建设更多公路。

输入样例:

6 15
1 2 5
1 3 3
1 4 7
1 5 4
1 6 2
2 3 4
2 4 6
2 5 2
2 6 6
3 4 6
3 5 1
3 6 1
4 5 10
4 6 8
5 6 3

输出样例:

12

 第一个 prim 算法,我的AC:

采用了,最小堆 + prim,.

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>#define MaxVertex 1001
#define INFITY 100001
#define MinValue -1typedef struct ENode *Edge;
struct ENode{int V1, V2;int Weight;
};typedef struct GNode *MGraph;
struct GNode{int Nv;int Ne;int G[MaxVertex][MaxVertex];
};typedef struct Sign_Dist_VNode DistNode;
struct Sign_Dist_VNode{int V;int Weight;
};typedef struct Heap *MinHeap;
struct Heap{DistNode *Data;int Size;
};MGraph Build_Graph();
MGraph Init_Graph();
void Insert_Graph(MGraph M, Edge E);
MinHeap Init_Heap(int N);
void Creat_Heap(MGraph M, MinHeap H, int Vertex, bool* Visited, bool *collected);
void Push_Heap(MinHeap H, int index, int Weight, bool *collected);
void Counterpoise_Heap(MinHeap H, int index, int V, int Weight);
bool IsEmpty_Heap(MinHeap H);
DistNode Pop_Heap(MinHeap H, bool *collected);
void Prim(MGraph M, MinHeap H, bool* Visited, int *dist);
void Print_Result(int N, int *dist, bool* Visited);int main()
{MGraph M;MinHeap H;int *dist;bool *Visited;M = Build_Graph();H = Init_Heap(M ->Nv);dist = (int*)malloc(sizeof(int) * M ->Nv);Visited = (bool*)calloc(M ->Nv, sizeof(bool));Prim(M, H, Visited, dist);Print_Result(M ->Nv, dist, Visited);return 0;
}void Prim(MGraph M, MinHeap H, bool* Visited, int *dist)
{int j;bool *collected;collected = (bool*)calloc(M ->Nv, sizeof(bool));for(j = 1; j < M ->Nv; j++){dist[j] = M ->G[0][j];}DistNode Data;Creat_Heap(M, H, 0, Visited, collected);Visited[0] = true;dist[0] = 0;while(Data = Pop_Heap(H, collected), Data.Weight > 0){Visited[Data.V] = true;for(j = 0; j < M ->Nv; j++){if(!Visited[j] && M ->G[Data.V][j] < INFITY && (dist[j] > M ->G[Data.V][j])){dist[j] = M ->G[Data.V][j];Push_Heap(H, j, dist[j], collected);//有人会问,这样不会产生数据重复吗,注意Visited,遵循一次访问原则。}}}
}
void Print_Result(int N, int *dist, bool* Visited)
{int i, cost = 0;for(i = 0; i < N; i++){if(!Visited[i]){printf("-1\n");return ;}cost += dist[i];}printf("%d\n", cost);return ;
}
MGraph Build_Graph()
{MGraph M;Edge E;M = Init_Graph();E = (Edge)malloc(sizeof(struct ENode));for(int i = 0; i < M ->Ne; i++){scanf("%d %d %d", &E ->V1, &E ->V2, &E ->Weight);E ->V1 --; E ->V2 --;Insert_Graph(M, E);}return M;
}
MGraph Init_Graph()
{MGraph M;M = (MGraph)malloc(sizeof(struct GNode));scanf("%d %d", &M ->Nv, &M ->Ne);for(int i = 0; i < (M ->Nv); i++){for(int j = 0; j < (M ->Nv); j++){M ->G[i][j] = INFITY;}}return M;
}
void Insert_Graph(MGraph M, Edge E)
{M ->G[E ->V1][E ->V2] = E ->Weight;M ->G[E ->V2][E ->V1] = E ->Weight;
}void Creat_Heap(MGraph M, MinHeap H, int Vertex, bool* Visited, bool *collected)
{for(int j = 0; j < M ->Nv; j++){if(M ->G[Vertex][j] < INFITY && !Visited[j]){Push_Heap(H, j, M ->G[Vertex][j], collected);}}
}
MinHeap Init_Heap(int N)
{MinHeap H;H = (MinHeap)malloc(sizeof(struct Heap));H ->Data = (DistNode*)malloc(sizeof(DistNode) * (N + 1));H ->Data[0].Weight = MinValue;H ->Size = 0;return H;
}
void Push_Heap(MinHeap H, int index, int Weight, bool *collected)
{int i;if(collected[index]){for(i = 1; i <= H ->Size; i++){if(index == H ->Data[i].V){H ->Data[i].Weight = Weight;Counterpoise_Heap(H, index, i, Weight);return ;}}}else{i = ++(H ->Size);Counterpoise_Heap(H, index, i, Weight);collected[index] = true;return ;}	
}
void Counterpoise_Heap(MinHeap H, int index, int i, int Weight)
{for(; Weight < H ->Data[i/2].Weight; i /= 2){H ->Data[i].Weight = H ->Data[i/2].Weight;H ->Data[i].V = H ->Data[i/2].V;}H ->Data[i].Weight = Weight;H ->Data[i].V = index;return ;
}
bool IsEmpty_Heap(MinHeap H)
{return (H ->Size == 0);
}
DistNode Pop_Heap(MinHeap H, bool *collected)
{DistNode Min, Temp;int Parent, Child;if(IsEmpty_Heap(H)){return H ->Data[0];}Min = H ->Data[1];Temp = H ->Data[H ->Size --];collected[Min.V] = false;for(Parent = 1; Parent *2 < H ->Size; Parent = Child){Child = Parent * 2;if(H ->Data[Child].Weight > H ->Data[Child + 1].Weight){Child++;}if(Temp.Weight <= H ->Data[Child].Weight){break;}else{H ->Data[Parent].Weight = H ->Data[Child].Weight;H ->Data[Parent].V = H ->Data[Child].V;}}H ->Data[Parent].Weight = Temp.Weight;H ->Data[Parent].V = Temp.V;return Min;
}

 第二个kruskal算法, 最小堆+并查树+Kruskal。

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>#define MaxVertex 1001
#define INFITY 100001
#define MinValue -1typedef struct ENode Edge;
struct ENode{int V1, V2;int Weight;
};typedef struct GNode *MGraph;
struct GNode{int Nv;int Ne;int G[MaxVertex][MaxVertex];
};typedef struct Heap *MinHeap;
struct Heap{Edge *Data;int Size;
};//便于并查树算法理解,有心吧。
typedef struct UnionFind *UF;
struct UnionFind{int Parent;
};MGraph Build_Graph();
MGraph Init_Graph();
void Insert_Graph(MGraph M, Edge E);
MinHeap Init_Heap(int N);
MinHeap Creat_Heap(MGraph M);
void Push_Heap(MinHeap H, int V1, int V2, int Weight);
bool IsEmpty_Heap(MinHeap H);
Edge Pop_Heap(MinHeap H);
UF Init_UnionFind(int VertexNum);
void Union_Value(UF T, int V1, int V2);
int Find_Root(UF T, int V);
bool Check_Loop(UF T, int V1, int V2);
void Kruskal(MGraph M, MinHeap H, UF T, bool *Visited, int *dist);int main()
{MGraph M;MinHeap H;UF T;int *dist;bool *Visited;M = Build_Graph();H = Creat_Heap(M);	T = Init_UnionFind(M ->Nv);dist = (int*)malloc(sizeof(int) * M ->Nv);Visited = (bool*)calloc(M ->Nv, sizeof(bool));Kruskal(M, H, T, Visited, dist);return 0;
}
void Kruskal(MGraph M, MinHeap H, UF T, bool *Visited, int *dist)
{Edge Data;int i = 1;int cost = 0;while(Data = Pop_Heap(H), (Data.Weight > 0 && i < M ->Nv)){if(!Check_Loop(T, Data.V1, Data.V2)){Union_Value(T, Data.V1, Data.V2);cost += Data.Weight;i++;}}if(i != M ->Nv){printf("-1\n");}else{printf("%d\n", cost);}
}MGraph Build_Graph()
{MGraph M;Edge E;M = Init_Graph();for(int i = 0; i < M ->Ne; i++){scanf("%d %d %d", &E.V1, &E.V2, &E.Weight);E.V1 --; E.V2 --;Insert_Graph(M, E);}return M;
}
MGraph Init_Graph()
{MGraph M;M = (MGraph)malloc(sizeof(struct GNode));scanf("%d %d", &M ->Nv, &M ->Ne);for(int i = 0; i < (M ->Nv); i++){for(int j = 0; j < (M ->Nv); j++){M ->G[i][j] = INFITY;}}return M;
}
void Insert_Graph(MGraph M, Edge E)
{M ->G[E.V1][E.V2] = E.Weight;M ->G[E.V2][E.V1] = E.Weight;
}MinHeap Creat_Heap(MGraph M)
{MinHeap H;H = Init_Heap(M ->Ne);for(int i = 0; i < M ->Nv; i++)for(int j = i + 1; j < M ->Nv; j++){if(M ->G[i][j] < INFITY){Push_Heap(H, i, j, M ->G[i][j]);}}return H;
}
MinHeap Init_Heap(int N)
{MinHeap H;H = (MinHeap)malloc(sizeof(struct Heap));H ->Data = (Edge*)malloc(sizeof(Edge) * (N + 1));H ->Data[0].Weight = MinValue;H ->Size = 0;return H;
}
void Push_Heap(MinHeap H, int V1, int V2, int Weight)
{int i;i = ++(H ->Size);for(; Weight < H ->Data[i/2].Weight; i /= 2){H ->Data[i].Weight = H ->Data[i/2].Weight;H ->Data[i].V1 = H ->Data[i/2].V1;H ->Data[i].V2 = H ->Data[i/2].V2;}H ->Data[i].Weight = Weight;H ->Data[i].V1 = V1;H ->Data[i].V2 = V2;return ;	
}bool IsEmpty_Heap(MinHeap H)
{return (H ->Size == 0);
}
Edge Pop_Heap(MinHeap H)
{Edge Min, Temp;int Parent, Child;if(IsEmpty_Heap(H)){return H ->Data[0];}Min = H ->Data[1];Temp = H ->Data[H ->Size --];for(Parent = 1; Parent *2 < H ->Size; Parent = Child){Child = Parent * 2;if(H ->Data[Child].Weight > H ->Data[Child + 1].Weight){Child++;}if(Temp.Weight <= H ->Data[Child].Weight){break;}else{H ->Data[Parent].Weight = H ->Data[Child].Weight;H ->Data[Parent].V1 = H ->Data[Child].V1;H ->Data[Parent].V2 = H ->Data[Child].V2;}}H ->Data[Parent].Weight = Temp.Weight;H ->Data[Parent].V1 = Temp.V1;H ->Data[Parent].V2 = Temp.V2;return Min;
}
UF Init_UnionFind(int VertexNum)
{UF T;T = (UF)malloc(sizeof(struct UnionFind) * (VertexNum + 1));for(int i = 0; i < VertexNum; i++){T[i].Parent = -1;}return T;
}
void Union_Value(UF T, int V1, int V2)
{int Root1, Root2;Root1 = Find_Root(T, V1);Root2 = Find_Root(T, V2);if(T[Root1].Parent < T[Root2].Parent){T[Root1].Parent += T[Root2].Parent;T[Root2].Parent = Root1;}else{T[Root2].Parent += T[Root1].Parent;T[Root1].Parent = Root2;}
}
int Find_Root(UF T, int V)
{if(T[V].Parent < 0){return V;}return Find_Root(T, T[V].Parent);
}
bool Check_Loop(UF T, int V1, int V2)
{if(Find_Root(T, V1) == Find_Root(T, V2)){return true;}else{return false;}
}

2024.9.6-错误借鉴,哈哈,我竟然,好吧,就是没有好好听课,不是最短路,而是最小边,之前的样例我感觉只是运气吧。

测试点提示内存(KB)用时(ms)结果得分
0sample换数字,各种回路判断1844

答案正确

15 / 15
1M<N-1,不可能有生成树1884

答案正确

2 / 2
2M达到N-1,但是图不连通3164

答案正确

2 / 2
3最大N和M,连通41568

答案错误

0 / 5
4最大N和M,不连通41567

答案正确

6 / 6

void Prim(MGraph M, MinHeap H, bool* Visited, int *dist)
{int j;bool *collected;collected = (bool*)calloc(M ->Nv, sizeof(bool));for(j = 0; j < M ->Nv; j++){dist[j] = INFITY;}DistNode Data;Creat_Heap(M, H, 0, Visited, collected);Visited[0] = true;dist[0] = 0;while(Data = Pop_Heap(H, collected), Data.Weight > 0){if(!Visited[Data.V] && dist[Data.V] > Data.Weight){dist[Data.V] = Data.Weight;}Visited[Data.V] = true;for(j = 0; j < M ->Nv; j++){if(!Visited[j] && M ->G[Data.V][j] < INFITY && (dist[j] > dist[Data.V] + M ->G[Data.V][j])){dist[j] = M ->G[Data.V][j];Push_Heap(H, j, dist[j], collected);//有人会问,这样不会产生数据重复吗,注意Visited,遵循一次访问原则。}}}	
}


文章转载自:
http://dinncoclamber.ydfr.cn
http://dinncoshingly.ydfr.cn
http://dinncoarmigerous.ydfr.cn
http://dinncoscrapnel.ydfr.cn
http://dinncovaccinization.ydfr.cn
http://dinncohipline.ydfr.cn
http://dinncodung.ydfr.cn
http://dinncoiritis.ydfr.cn
http://dinncohogman.ydfr.cn
http://dinncocasserole.ydfr.cn
http://dinncoconjunctly.ydfr.cn
http://dinncolunate.ydfr.cn
http://dinnconephrogenic.ydfr.cn
http://dinncosaturable.ydfr.cn
http://dinncoflipping.ydfr.cn
http://dinncoinsensate.ydfr.cn
http://dinncopedrail.ydfr.cn
http://dinncoexcommunicative.ydfr.cn
http://dinncobimorphemic.ydfr.cn
http://dinncolimaceous.ydfr.cn
http://dinncoparatroop.ydfr.cn
http://dinncoshy.ydfr.cn
http://dinncobutylene.ydfr.cn
http://dinncotriskelion.ydfr.cn
http://dinncodiary.ydfr.cn
http://dinncodowsabel.ydfr.cn
http://dinncocontrarious.ydfr.cn
http://dinncowrastle.ydfr.cn
http://dinncoemulsoid.ydfr.cn
http://dinncostave.ydfr.cn
http://dinncolocknut.ydfr.cn
http://dinncovarmint.ydfr.cn
http://dinncomzungu.ydfr.cn
http://dinncoinhabitance.ydfr.cn
http://dinncodeadpan.ydfr.cn
http://dinncointercostal.ydfr.cn
http://dinncocascaron.ydfr.cn
http://dinncoblastissimo.ydfr.cn
http://dinncoparodist.ydfr.cn
http://dinncodisilicate.ydfr.cn
http://dinncounderclothes.ydfr.cn
http://dinncooverwear.ydfr.cn
http://dinncobhc.ydfr.cn
http://dinncoqktp.ydfr.cn
http://dinncotantalite.ydfr.cn
http://dinncofastidiousness.ydfr.cn
http://dinncodecinormal.ydfr.cn
http://dinncolapsus.ydfr.cn
http://dinncophosphorolysis.ydfr.cn
http://dinncotideland.ydfr.cn
http://dinncokneel.ydfr.cn
http://dinncosnippety.ydfr.cn
http://dinncodownpress.ydfr.cn
http://dinncoeiffel.ydfr.cn
http://dinncomathematic.ydfr.cn
http://dinncoazonal.ydfr.cn
http://dinncocomposition.ydfr.cn
http://dinncoelegiast.ydfr.cn
http://dinncoelephantiac.ydfr.cn
http://dinncolemme.ydfr.cn
http://dinncoseller.ydfr.cn
http://dinncomahren.ydfr.cn
http://dinncomaxiskirt.ydfr.cn
http://dinncocacodemon.ydfr.cn
http://dinncoopiology.ydfr.cn
http://dinncotrackside.ydfr.cn
http://dinncochicago.ydfr.cn
http://dinncoclassic.ydfr.cn
http://dinncotroutling.ydfr.cn
http://dinncogaiseric.ydfr.cn
http://dinncoroutinization.ydfr.cn
http://dinncoisoperimetry.ydfr.cn
http://dinncolombard.ydfr.cn
http://dinncokiblah.ydfr.cn
http://dinncoalbion.ydfr.cn
http://dinncoinitiate.ydfr.cn
http://dinncoprometheus.ydfr.cn
http://dinncosophonias.ydfr.cn
http://dinncoweregild.ydfr.cn
http://dinncosportsman.ydfr.cn
http://dinncosentential.ydfr.cn
http://dinncoinitializers.ydfr.cn
http://dinncolitterbin.ydfr.cn
http://dinncobedquilt.ydfr.cn
http://dinncoalgesia.ydfr.cn
http://dinncosympathizer.ydfr.cn
http://dinncowoorali.ydfr.cn
http://dinncoschist.ydfr.cn
http://dinncowaterguard.ydfr.cn
http://dinncoboulevard.ydfr.cn
http://dinncoexecutory.ydfr.cn
http://dinncosinuosity.ydfr.cn
http://dinncotumultuously.ydfr.cn
http://dinncoreeb.ydfr.cn
http://dinncosilicide.ydfr.cn
http://dinncoinduplicate.ydfr.cn
http://dinncohorseshoe.ydfr.cn
http://dinncogrudge.ydfr.cn
http://dinncocorona.ydfr.cn
http://dinncoungovernable.ydfr.cn
http://www.dinnco.com/news/132517.html

相关文章:

  • 网站建设 pdf教育机构在线咨询
  • 西安网站制作资源seo咨询解决方案
  • 海口澄迈县建设局网站班级优化大师免费下载学生版
  • vi设计的目的郑州seo博客
  • 石家庄网站建设推广电话上海疫情突然消失的原因
  • 电子商务网站软件建设的核心是什么百度搜索引擎营销
  • dede静态网站模板下载全网营销一站式推广
  • wordpress member only东莞百度seo
  • 海口 网站制作公司北京百度seo排名
  • 做优化的网站专门代写平台
  • 企业网站建设服务内容谷歌推广app
  • 德清县住房和城乡建设局网站seo公司怎么推广宣传
  • behance设计网站怎么念厦门seo厦门起梦
  • 做垃圾网站可行吗网页制作代码
  • html制作电影网站网络外包运营公司
  • 17做网店网站百度集团公司简介
  • 做网站主流语言网络营销的核心
  • 做网站致富博客网站登录
  • 建设项目立项网站今日要闻10条
  • 仿漫画网站建设定制小说网站系统源码建设seo专业培训机构
  • 试百客 专业做试用的网站seo怎么刷关键词排名
  • 黑龙江省建设工程招标网站数字营销策略有哪些
  • 出国做博士后网站做一个公司网页多少钱
  • 做宣传单用什么网站产品软文范例大全
  • 松原做网站公司网络营销运营策划
  • 域名出售后被用来做非法网站网站搜索系统
  • 非物质文化遗产网站怎么做网络营销策划包括哪些内容
  • 做网站打开图片慢青岛模板建站
  • 网站不做301可以吗宁波seo外包引流推广
  • cnzz 网站域名怎么填厦门谷歌seo