随笔分类 - 图论—最小生成树
摘要:这个题要交c++, 因为prime的返回值错了,改了一会题目:http://poj.org/problem?id=2031题意:就是给出三维坐标系上的一些球的球心坐标和其半径,搭建通路,使得他们能够相互连通。如果两个球有重叠的部分则算为已连通,无需再搭桥。求搭建通路的最小费用(费用就是边权,就是两个...
阅读全文
摘要:有几个错误,调试了几个小时,样例过后 1Y.题目:http://poj.org/problem?id=3026题意:就是让求A们和S的最小生成树先用bfs找每两点的距离,再建树。没剪枝 63MS。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std; 10 11 char G[60][60]; 12 int dx[5]={0,0,1,-1}; 13 int dy[5]={1,-1,...
阅读全文
摘要:题目:http://poj.org/problem?id=1258题意:模板题 和2485差不多 就是求相连后的最小值。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 int bin[110];11 struct node12 {13 int u,v,w;14 } q[30000];15 bool cmp(node x,node y)16 {17 return x.w...
阅读全文
摘要:这题挺无语啊,在poj上交c++就wrong,用cin输入就会TLE;看来以后要交G++,用scanf输入了题目:http://poj.org/problem?id=2485题意:求最小生成树的边的最长边 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 int bin[510];11 struct node12 {13 int u,v,w;14 } q[251000];15 boo...
阅读全文
摘要:模板题题目:http://poj.org/problem?id=1789题意:有n个型号,每个型号有7个字母代表其型号,每个型号之间的差异是他们字符串中对应字母不同的个数d[ta,tb]代表a,b之间的差异数问1/Σ(to,td)d(to,td)最大值prime: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 int grah[2100][2100];12 int sum=0;13 void pim(int .
阅读全文
摘要:题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2144&cid=1186 1 #include 2 #include 3 #include 4 int bin[110]; 5 struct node 6 { 7 int u,v,w; 8 }q[10001]; 9 10 int cmp(const void *a,const void *b)//按距离从小到大排序11 {12 return (*(node *)a).w-(*(node *)b).w;13 }14 int find(int a)15 {16 if(a...
阅读全文
摘要:普里姆算法(稠密图) 克鲁斯卡尔算法(稀疏图)1.prime 算法贪心 集合加点2.Kruskal算法并查集 加边http://acm.hdu.edu.cn/showproblem.php?pid=1233 思想是加 点,在边比较多的情况下,用prime。思路:先找 任意一点到其他的点的 最短距离...
阅读全文

浙公网安备 33010602011771号