题目描述:

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. 创建多线程的第一种方式——创建Thread子类和重写run方法

    创建多线程的第一种方式——创建Thread子类和重写run方法: 第二种方式——实现Runnable接口,实现类传参给父类Thread类构造方法创建线程: 第一种方式创建Thread子类和重写run方 ...

  2. 牛客网 完数VS盈数

    题目链接:https://www.nowcoder.com/practice/ccc3d1e78014486fb7eed3c50e05c99d?tpId=40&tqId=21351&t ...

  3. Python assert断言

    assert断言:指定某个对象判断类型,不成立则报错. 使用环境  :接下来程序的执行,如果依赖前面的类型,不能报错的情况下使用. assert type(obj) is str print(&quo ...

  4. Linux 系统开启最大线程数 调优

    系统最大线程数说明 系统可开启的最大线程数,可根据系统本身负载配置进行调优. 查看系统最大线程数 1.查看系统开启的最大线程数. ulimit -u [root@izbp1brwu1w35r1dmj8 ...

  5. win7下Oracle库impdp导入dmp

    第一步:创建备份文件存储目录 create or replace directory back_file as 'D:\app\yangxf\back_or_memery_file'; create ...

  6. LINQ之路12:LINQ Operators之数据转换(Projecting)

    本篇继续LINQ Operators的学习,这里我们讨论的是数据转换的两种方式:Select和SelectMany,看似简单常用的两种运算符,却也大有讲究.我们会在本篇详细介绍他们的使用方式和适用的场 ...

  7. Codeforces 40 E. Number Table

    题目链接:http://codeforces.com/problemset/problem/40/E 妙啊... 因为已经确定的格子数目严格小于了$max(n,m)$,所以至少有一行或者一列是空着的, ...

  8. C#以太坊基础入门

    在这一部分,我们将使用C#开发一个最简单的.Net控制台应用,来接入以太坊节点,并打印 所连接节点旳版本信息.通过这一部分的学习,你将掌握以下技能: 如何使用节点仿真器 如何在命令行访问以太坊节点 如 ...

  9. robot framework学习二-----元素定位

    文章摘自:https://www.cnblogs.com/fnng/p/3901391.html 不要误认为Robot framework 只是个web UI测试工具,更正确的理解Robot fram ...

  10. 新建vue项目中遇到的报错信息

    在npm install的时候会报错,经过上网查阅资料之后,解决方法如下: 0.先升级npm版本:npm install -g npm   有可能是npm版本过低报错 1.然后清理缓存: npm ca ...