设为首页 加入收藏

TOP

HDU 1875 畅通工程再续 (最小生成树 水)
2015-07-20 17:57:35 来源: 作者: 【 】 浏览:3
Tags:HDU 1875 畅通 工程 最小 生成


Problem Description 相信大家都听说一个“百岛湖”的地方吧,百岛湖的居民生活在不同的小岛中,当他们想去其他的小岛时都要通过划小船来实现。现在政府决定大力发展百岛湖,发展首先要解决的问题当然是交通问题,政府决定实现百岛湖的全畅通!经过考察小组RPRush对百岛湖的情况充分了解后,决定在符合条件的小岛间建上桥,所谓符合条件,就是2个小岛之间的距离不能小于10米,也不能大于1000米。当然,为了节省资金,只要求实现任意2个小岛之间有路通即可。其中桥的价格为 100元/米。


Input 输入包括多组数据。输入首先包括一个整数T(T <= 200),代表有T组数据。
每组数据首先是一个整数C(C <= 100),代表小岛的个数,接下来是C组坐标,代表每个小岛的坐标,这些坐标都是 0 <= x, y <= 1000的整数。


Output 每组输入数据输出一行,代表建桥的最小花费,结果保留一位小数。如果无法实现工程以达到全部畅通,输出”oh!”.


Sample Input
2
2
10 10
20 20
3
1 1
2 2
1000 1000


Sample Output
1414.2
oh!


总共最多有100个节点,那么边最大100*100/2,把所有 符合题意 的边都求出来,然后就是最小生成树了。


#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #define lson o<<1, l, m #define rson o<<1|1, m+1, r using namespace std; typedef long long LL; const int maxn = 105; const int mod = 1000000007; int n, t, fa[105]; double q; struct C1{ int st, en; double v; }ed[6000]; struct C2 { int x, y; }in[105]; double getdis(double x1, double y1, double x2, double y2) { return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ); } bool cmp (C1 x, C1 y) { return x.v < y.v; } int Find (int x) { return x == fa[x] ? x : x = Find(fa[x]); } int main() { scanf("%d", &t); while(t--) { int n; scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d%d", &in[i].x, &in[i].y); int k = 0; for(int i = 0; i < n-1; i++) for(int j = i+1; j < n; j++) { double tmp = getdis(in[i].x, in[i].y, in[j].x, in[j].y); if(tmp >= 10 && tmp <= 1000) { ed[k].v = tmp*100; ed[k].st = i; ed[k++].en = j; } } sort(ed, ed+k, cmp); for(int i = 0; i <= 100; i++) fa[i] = i; double sum = 0; int cnt = 0; for(int i = 0; i 
       
        


??
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 1171 Big Event in HDU(多重.. 下一篇UVA - 620Cellular Structure(递..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: