题目描述:

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. centos7使用yum安装软件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解决方法

    由于是本地yum源安装软件,无法联网,因此使用yum安装软件时报了错,解决方法是: 打开vi /etc/resolv.conf文件 新增内容如下: nameserver 8.8.8.8 nameser ...

  2. List 循环删除 指定元素的 方法

    使用Iterator进行循环,在删除指定元素.如果使用for 或 foreach 在删除指定下标是,list.size 会相应的缩短且下标前移,导致相邻满足条件的元素未删除 Iterator<S ...

  3. Windows cmd 一些命令

    运行是Windows的必要组成部分,可以简单理解为一个应用程序快速调用的组件.通过“运行”窗口,可以调用Windows中任何应用程序甚至DOS命令.一般可以搜索百度百科 微软件(窗口) + R    ...

  4. nodejs cannot find module 'mysql' 问题分析

    在windows平台下,测试nodejs连接mysql数据库. 首先 在控制台中安装mysql依赖包 npm install mysql 安装成功后,mysql依赖包可以在User目录中的node_m ...

  5. C++的重载操作符(operator)介绍(转)

    本文主要介绍C++中的重载操作符(operator)的相关知识. 1. 概述 1.1 what operator 是C++的一个关键字,它和运算符(如=)一起使用,表示一个运算符重载函数,在理解时可将 ...

  6. 时间序列数据库调研之InfluxDB

    基于 Go 语言开发,社区非常活跃,项目更新速度很快,日新月异,关注度高 测试版本 1.0.0_beta2-1 安装部署 wget https://dl.influxdata.com/influxdb ...

  7. JNI与底层调用

    交叉编译 在一个平台下,编译出另一个平台能够执行的二进制的代码 平台:windows,mac os,linux 处理器:x86,arm,mips 交叉编译的原理 源代码->编译->链接-& ...

  8. 剑指offer(30)连续子数组和的最大值

    题目描述 HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学.今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决.但是,如果向量 ...

  9. 2018.9.25 NOIP模拟赛

    *注意:这套题目应版权方要求,不得公示题面. 从这里开始 Problem A XOR Problem B GCD Problem C SEG 表示十分怀疑出题人水平,C题数据和标程都是错的.有原题,差 ...

  10. Delphi10.2 Tokyo试用(1)

    最近下载了Delphi10.2 Tokyo,试用了一下,感觉不错,尤其是针对Linux的开发,总算出来了,可以考虑把原来服务器重新编译成RedHat上使用了,免得客户一天到晚喊Windows不安全,要 ...