Sample Input
2
2
10 10 //坐标
20 20
3
1 1
2 2
1000 1000

Sample Output
1414.2   //最小权值和*100  保留1位小数
oh!       //不连通

prim

 # include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <cmath>
# define LL long long
using namespace std ; const int INF=0x3f3f3f3f;
const int MAXN=;
bool vis[MAXN];
double lowc[MAXN];
int n ;
double cost[MAXN][MAXN] ; struct poin
{
int x ;
int y ;
}p[]; double Prim()//点是0~n-1
{
double ans=;
memset(vis,false,sizeof(vis));
vis[]=true;
for(int i=;i<n;i++)lowc[i]=cost[][i];
for(int i=;i<n;i++)
{
double minc=INF;
int p=-;
for(int j=;j<n;j++)
if(!vis[j]&&minc>lowc[j])
{
minc=lowc[j];
p=j;
}
if(minc==INF)return -;//原图不连通
ans+=minc;
vis[p]=true;
for(int j=;j<n;j++)
if(!vis[j]&&lowc[j]>cost[p][j])
lowc[j]=cost[p][j];
}
return ans;
} int main()
{ // freopen("in.txt","r",stdin) ;
int T ;
scanf("%d" , &T) ;
while(T--)
{
scanf("%d" , &n) ;
int i , j ;
for (i = ; i < n ; i++)
for (j = ; j < n ; j++)
cost[i][j] = INF ;
for (i = ; i < n ; i++)
scanf("%d %d" , &p[i].x , &p[i].y) ;
for (i = ; i < n ; i++)
for (j = i+ ; j < n ; j++)
{
double t = sqrt((double)(p[i].x - p[j].x) * (p[i].x - p[j].x) + (p[i].y - p[j].y) * (p[i].y - p[j].y)) ;
if (t <10.0 || t > 1000.0)
continue ;
cost[i][j] = t ;
cost[j][i] = t ;
}
double k = Prim() ;
if (k == -)
printf("oh!\n") ;
else
printf("%.1lf\n" , k*) ; }
return ;
}

hdu 1875 给出每个结点的坐标 权值为两点间的距离 (MST)的更多相关文章

  1. HDU 2001 计算两点间的距离

    http://acm.hdu.edu.cn/showproblem.php?pid=2001 Problem Description 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离 ...

  2. HDOJ/HDU 2547 无剑无我(两点间的距离)

    Problem Description 北宋末年,奸臣当道,宦官掌权,外侮日亟,辽军再犯.时下战火连连,烽烟四起,哀鸿遍野,民不聊生,又有众多能人异士群起而反,天下志士云集响应,景粮影从. 值此危急存 ...

  3. hdu 1853 Cyclic Tour (二分匹配KM最小权值 或 最小费用最大流)

    Cyclic Tour Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)Total ...

  4. HDU 1853 Cyclic Tour[有向环最小权值覆盖]

    Cyclic Tour Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)Total ...

  5. HDU 6214 Smallest Minimum Cut 最小割,权值编码

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这 ...

  6. HDU 6464.免费送气球-动态开点-权值线段树(序列中第first小至第second小的数值之和)(感觉就是只有一个状态的主席树) (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)

    免费送气球 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  7. HDU - 2665 Kth number 主席树/可持久化权值线段树

    题意 给一个数列,一些询问,问$[l,r]$中第$K$大的元素是哪一个 题解: 写法很多,主席树是最常用的一种之一 除此之外有:划分树,莫队分块,平衡树等 主席树的定义其实挺模糊, 一般认为就是可持久 ...

  8. hdu 1875 畅通project再续

    链接:hdu 1875 输入n个岛的坐标,已知修桥100元/米,若能n个岛连通.输出最小费用,否则输出"oh!" 限制条件:2个小岛之间的距离不能小于10米,也不能大于1000米 ...

  9. poj 2031 给出每个结点的3维坐标 以及结点的半径 (MST)

    3维空间中有N个圆球,给出x y z 以及圆球的半径 ,求最小生成树 边的权值为两个圆球间的距离 如果圆球相互接触 则权值为0 求最小的权值和 Sample Input 3 //n10.000 10. ...

随机推荐

  1. Bootstrap -- 文件上传插件File Input的使用

    BootstrapFileInput下载参考:http://www.jq22.com/jquery-info5231 网友经验参见:http://www.cnblogs.com/wuhuacong/p ...

  2. Python中的包ImportError

    前言 Python中的包给我提供了很好的代码组织,相似的功能模块放在同一个包内,不仅代码结构清晰,而且调用起来也比较方便(可以用*导入) 但是,我们在刚开始使用Python包的时候总是会遇到导入错误& ...

  3. leetCode- 472. Concatenated Words

    因为每个组合的字符串,至少要有3个index. 起点,中间拼接点,结点.所以可以将字符串分解为子字符串,判断子字符串是否存在.但是,后面字符串的存在必须要在前面字符串已经存在基础上判断. class ...

  4. C# 摇奖机实例(线程)

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. pyqt5-键盘事件

    视频教程:https://v.qq.com/x/page/p08592bhsag.html keyPressEvent(QKeyEvent)    键盘按下时调用 keyReleaseEvent(QK ...

  6. 第14月第30天 svn 撤销ignore revert

    1. 直接到被ignore的位置,执行: svn add <你被ignore的文件名> --no-ignore –no-ignore是取消忽略 如果是add目录,你可以: svn add ...

  7. WARN bzip2.Bzip2Factory: Failed to load/initialize native-bzip2 library system-native, will use pure-Java version

    [root@hdp2 /root]#hadoop checknative -a 18/12/09 00:31:19 WARN bzip2.Bzip2Factory: Failed to load/in ...

  8. static extern

    /*主程序在a.c*/ //a.c #include <stdio.h> #include "b.h" main(){ printf ("%d\n" ...

  9. HTML5实现全屏API【进入和退出全屏】

    现在主流浏览器基本上实现了全屏效果,但是不同浏览器实现不一样: [进入和退出全屏] // Webkit (works in Safari5.1 and Chrome 15)element.webkit ...

  10. Django学习手册 - 自定义simple_tag / filter

    相关: Django的模板引擎提供一般性的功能函数,通过前端可以实现多数的代码逻辑功能,但它仅支持大多数常见情况下的函数功能,例如if判断,ifequal对比返回值等,复杂一些的函数功能并不支持,例如 ...