摘要:
思路:见代码吧。#include #include #include #include #include using namespace std;const int maxn=2010;int n,m;int father[maxn];int num[maxn]; //num[i]表示int rel[maxn]; //rel[i]表示它与根节点的关系,0代表同性,1代表异性void init(){ for(int i=0;inum[y]){ father[y]=x; num[x]+=num[y]; //更新y与根节点x的关系 rel... 阅读全文
posted @ 2013-09-01 21:37
辰曦~文若
阅读(271)
评论(0)
推荐(0)
摘要:
想到枚举m个点,然后求最小生成树,ratio即为最小生成树的边权/总的点权。但是怎么枚举这m个点,实在不会。网上查了一下大牛们的解法,用dfs枚举,没想到dfs还有这么个作用。参考链接:http://blog.csdn.net/xingyeyongheng/article/details/9373271#include #include #include #include #include using namespace std;const int INF=0x3f3f3f3f;int n,m,tot; //tot为选取的m个点的总权值int choseNode[16]; //存储选取的m个. 阅读全文
posted @ 2013-09-01 16:26
辰曦~文若
阅读(556)
评论(0)
推荐(0)
摘要:
一开始想到用BFS,写了之后,发现有点不太行。网上查了一下别人的解法。首先将边从小到大排序,然后从最小边开始枚举,每次取比它大的边,直到start、end属于同一个集合,即可以连通时停止。过程类似于最小生成树。舒适感即为选取的最后一条边减去一开始的那条边,所有情况取最小值。#include #include #include #include #include #include #include using namespace std;const int INF=0x3f3f3f3f;const int maxn=211;const int maxm=1010;int n,m,q,ans,s, 阅读全文
posted @ 2013-09-01 14:08
辰曦~文若
阅读(216)
评论(0)
推荐(0)

浙公网安备 33010602011771号