题目描述:

In an episode of the Dick Van Dyke show, little Richie connects the freckles on his Dad's back to form a picture of the Liberty Bell. Alas, one of the freckles turns out to be a scar, so his Ripley's engagement falls through. 
    Consider Dick's back to be a plane with freckles at various (x,y)
locations. Your job is to tell Richie how to connect the dots so as to
minimize the amount of ink used. Richie connects the dots by drawing
straight lines between pairs, possibly lifting the pen between lines.
When Richie is done there must be a sequence of connected lines from any
freckle to any other freckle.

输入:

The first line contains 0 < n <=
100, the number of freckles on Dick's back. For each freckle, a line
follows; each following line contains two real numbers indicating the
(x,y) coordinates of the freckle.

输出:

Your program prints a single real
number to two decimal places: the minimum total length of ink lines that
can connect all the freckles.

样例输入:
3
1.0 1.0
2.0 2.0
2.0 4.0
样例输出:
3.41

这道题就是输入n,和n个坐标

然后输出将所有点连起来的最短路径

还是最小生成树

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int path[]; struct edge{
int a,b;
double cost;
bool operator <(const edge &A) const{
return cost<A.cost;
}
}edge[]; int findroot(int a){
int temp=a;
while (path[a] != -){
a=path[a];
}
int temp2; while (path[temp]!= -){
temp2=path[temp];
path[temp]=a;
temp=temp2;
}
return a;
} int main (){
int n;
double point[][];
while (cin>>n){
int size=;
for (int i=;i<=n;i++){
cin>>point[i][]>>point[i][];
for (int j=;j<i;j++){
edge[size].a=i;
edge[size].b=j;
edge[size].cost=sqrt(pow(point[i][]-point[j][],2.0)+pow(point[i][]-point[j][],2.0));
size++;
}
} int nn=n*(n-)/;
for (int i=;i<=n;i++){
path[i]=-;
}
double ans=; sort(edge+,edge++nn);
int a,b;
for (int i=;i<=nn;i++){
a=edge[i].a;
b=edge[i].b;
a=findroot(a);
b=findroot(b);
if (a!=b){
path[a]=b;
ans += edge[i].cost;
}
} printf("%.2lf\n",ans);//输出精确到两位小数
}
return ; }
//图论的edge什么的下标都是从1开始的,而不是0比较方便

学会了输出两位小数怎么做

freckles的更多相关文章

  1. 10034 - Freckles 克鲁斯克尔最小生成树!~

    /* 10034 - Freckles 克鲁斯克尔最小生成树!- */ #include<iostream> #include<cstdio> #include<cmat ...

  2. poj 2560 Freckles

    题目连接 http://poj.org/problem?id=2560 Freckles Description In an episode of the Dick Van Dyke show, li ...

  3. 题目1144:Freckles(最小生成树进阶)

    题目链接:http://ac.jobdu.com/problem.php?pid=1144 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  4. 九度OJ 1144:Freckles(斑点) (最小生成树)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1538 解决:760 题目描述: In an episode of the Dick Van Dyke show, little Richi ...

  5. POJ2560 Freckles

    Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu Description In an epis ...

  6. 【九度OJ】题目1144:Freckles 解题报告

    [九度OJ]题目1144:Freckles 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1144 题目描述: In an ...

  7. UVA 10034 Freckles 最小生成树

    虽然是道普通的最小生成树题目,可还是中间出了不少问题,暴露的一个问题是不够细心,不够熟练.所以这篇博客就当记录一下bug吧. 代码一:kruskal #include<stdio.h> # ...

  8. uva 10034 Problem A: Freckles

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  9. POJ 2560 Freckles Prime问题解决算法

    这个问题正在寻求最小生成树. 给定节点的坐标,那么我们需要根据各个点之间的这些坐标来计算距离. 除了这是标准的Prime算法的,能源利用Prime基本上,你可以使用Kruskal. 经典的算法必须填写 ...

随机推荐

  1. JVM探秘1--JVM内存运行时区域划分

    Java程序员一般不需要太关注内存,因为操作内存的权力都交给了Java虚拟机,但是Java程序员必须需要了解JVM是如何使用内存的,否则一旦内存出现泄漏或事溢出的话,就会一筹莫展不知道从哪去入手排查问 ...

  2. 本地设置VirtualBox虚拟机

    主要是涉及到网卡设置,允许本地ping虚拟机

  3. js 图片无缝滚动

    html部分 <div id="roll"> <a href="javascript:void(0)" class="prev&qu ...

  4. pyCharm的第一个项目

    首先打开编译器pyCharm 创建一个项目 在location :新建文件夹 在interpreter:指定python解释器的路径 python解释器下载官网: https://www.python ...

  5. Shell if条件语句

    1.if条件语句:设定一个条件如果怎么,然后怎么样. (1)-gt大于.-lt小于.-ge大于等于.-le小于等于.-eq等于.-ne不等于. (2)[]内是包括变量时所使用的. (3)-f文件.-n ...

  6. oracle flashback data archive闪回数据归档天坑之XID重用导致闪回查询数据重复

    我们有个系统使用了Oracle flashback data archive闪回数据归档特性来作为基于时间点的恢复机制,在频繁插入.更新期间发现SYS_FBA_HIST_NNNN表中的XID被两个事务 ...

  7. 系统安装后的linux和vmware的网络配置

    一.1表示linux的版本   2表示linux内核的版本   3表示操作系统多少位  4.表示操作系统的名称 二.配置虚拟机网络 1.在办公室控制和使用服务器(机房) 2.远程连接 ###配置虚拟机 ...

  8. 【2.0】SpringBoot2配置Druid数据源及监控

    什么是Druid? Druid首先是Java语言中最好的数据库连接池,也是阿里巴巴的开源项目.Druid是阿里巴巴开发的号称为监控而生的数据库连接池,在功能.性能.扩展性方面,都超过其他数据库连接池, ...

  9. Learning-Python【33】:并发编程之多进程

    一.multiprocessing 模块介绍 Python 中的多线程无法利用多核优势,如果想要充分地使用多核 CPU 的资源(os.cpu_count()查看),在 Python 中大部分情况需要使 ...

  10. 6th-Python基础——集合、函数

    1.集合 主要作用: (1)去重 (2)关系测试,交集.差集difference().并集union().反向差集symmetric_difference().子集issubset().父集issup ...