最小生成树
smallacmer
这个作者很懒,什么都没留下…
展开
-
http://poj.org/problem?id=2075
DescriptionYou are the owner of SmallCableCo and have purchased the franchise rights for a small town. Unfortunately, you lack enough fu原创 2011-10-19 11:30:15 · 535 阅读 · 0 评论 -
Connect the Cities&&http://acm.hdu.edu.cn/showproblem.php?pid=3371
最小生成树变形题,不解释,这里输入量比较多,最好用一下输入外挂。。。AC代码:#include#include#include#include#include#include#include#define N 80000#define M 505using namespace std;typedef struct{ int x; int y;原创 2012-07-26 10:36:37 · 781 阅读 · 0 评论 -
http://acm.timus.ru/problem.aspx?space=1&num=1416&&次小生成树
这一题浪费了我不少时间啊,,,,很是伤心,,以前写过用prim添边删边的题,,于是果断安以前的方法去做结果是一个劲的wa,,,,,最后实在木办法了,就用krusal写 了一遍,结果很是给力,,过了,,Ac代码:#include#define N 250010#define M 99999999#includeusing namespace std;struct Node{in原创 2011-11-07 09:21:25 · 964 阅读 · 0 评论 -
http://poj.org/problem?id=2728&&最优比例生成树
首先解决这类问题一般有2种方法,,一是迭代法其次就是二分法,这里用到的主要是逼近的思想,,,这是题目的要求是一颗生成树,但不是要求边权之和最大,所以不能直接用最小生成树来求,但我们可以把其转发为一个熟悉的问题。设x1,x2,,,,,xm在集合{0,1}中取值,当且仅当xi=1时表示边i在生成树中出现,我们希望的是r = ∑(cost[i] * x[i])/∑(benifit[i] *原创 2011-11-05 17:50:59 · 748 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=118&&次小生成树
昨天做的次小生成树的用的是标记法,,,今天用的的是,,,,添边,删边法,,代码:#include#include#include#define N 501#define M 9999999#define MM -999999using namespace std;int map[N][N],maxs[N][N],dist[N];bool visit[N];int n,m;原创 2011-11-06 10:35:37 · 763 阅读 · 0 评论 -
http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?&&次小生成树
这是个次小生成树的题,首先介绍一下什么事次小生成树,,,就是存在有两个及以上的最小生成树,,,,这一题用krusal TLE。。。因此选用了prim算法,,,,思想就是:如果存在一个点i它的dist【i】可以由两个或两个以上的其他点更新得到,那么最小生成树肯定不唯一了,,,,法一:#include#include#define N 101#define M 99999999usin原创 2011-11-05 11:11:20 · 1165 阅读 · 0 评论 -
http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1004&ojid=2&cid=963&hide=0
#include#include#define N 101#define M 99999999.0#define FOR(i,s,t) for(int i=(s);i<=(t);++i)#includeusing namespace std;double map[N][N];double dist[N];bool visit[N];struct point{ double原创 2011-11-03 19:45:33 · 1299 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1162
最小生成树,水题。。。。。#include#define N 105#define M 9999999.0#define FOR(i,s,t) for(int i=(s);i<=(t);++i)#include#include#includeusing namespace std;double map[N][N];bool visit[N];double dist[N];i原创 2011-10-28 22:00:04 · 573 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1875
Problem Description相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现。现在政府决定大力发展百岛湖,发展首先要解决的问题当然是交通问题,政府决定实现百岛湖的全畅通!经过考察小组RPRush对百岛湖的情况充分了解后,决定在符合条件的小岛间建上桥,所谓符合条件,就是2个小岛之间的距离不能小于10米,也不能大于1000米原创 2011-10-21 20:06:45 · 592 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1879
该题依旧是最小生成树问题,只是有一点小小的变化。。。。。做完这题,猛然发现为什么prim算法优先于Kursal了。。。。。#include#include#include#include#define N 105#define FOR(i,s,t) for(int i=(s);i<=t;++i)using namespace std;int n,m;int father[N]原创 2011-10-21 17:26:23 · 627 阅读 · 0 评论 -
http://poj.org/problem?id=1861&&Kursal
DescriptionAndrew is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the company, they can be connected to each other using cables.原创 2011-10-20 12:28:53 · 550 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1863
这题也算是一道水题吧!我记得我以前是用Prim算法写的,现在用Kursal写一遍感觉还可以。。。。come on。。。Problem Description省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可)。经过调查评估,得到的统计表中列出了有可能建设公路的若干条道路的成本。现请你编写程序,计算出全省畅通需要的最低成原创 2011-10-21 09:55:41 · 632 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1232&&并查集应用
水题进行时。。。。加油(*^__^*) 嘻嘻……。。。#include#include#include#include#define N 1005#define FOR(i,s,t) for(int i=(s);i<=t;++i)using namespace std;int n,m,tot;int father[N];void make_set(){ FOR(i,1,n原创 2011-10-21 09:20:08 · 986 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1233&&Krusal
算是水题。。。。。但自己感觉水的不太好(*^__^*) 嘻嘻……come on #include#include#include#include#define N 5005#define FOR(i,s,t) for(int i=(s);i<=t;++i)using namespace std;int n,m;int father[N];struct edge{int x,y,原创 2011-10-21 09:36:23 · 620 阅读 · 0 评论 -
http://poj.org/problem?id=1287&&prim
DescriptionYou are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may conne原创 2011-10-20 13:04:12 · 575 阅读 · 0 评论 -
http://acm.nyist.net/JudgeOnline/problem.php?pid=38&&最小生成树
描述 南阳理工学院要进行用电线路改造,现在校长要求设计师设计出一种布线方式,该布线方式需要满足以下条件:1、把所有的楼都供上电。2、所用电线花费最少输入 第一行是一个整数n表示有n组测试数据。(n每组测试数据的第一行是两个整数v,e.v表示学校里楼原创 2011-10-18 13:29:43 · 627 阅读 · 0 评论 -
Air Ports&&http://www.lightoj.com/volume_showproblem.php?problem=1059
最小生成树变形,这一题,真他妈的恶心,由于没看清最后一句话,导致一直wa,,在修建机场和修路方面,如果修路的费用和修飞机场的相同,则优先考虑修飞机场,,法一:#include#include#include#include#define pf printf#include#define N 100005#define M 10005using namespace std;原创 2012-08-01 10:43:55 · 1078 阅读 · 0 评论