Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu

Description

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.

Input

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.

Output

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

Sample Input

3
1.0 1.0
2.0 2.0
2.0 4.0

Sample Output

3.41

Source

 
最小生成树。注意double
 
 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
const int mxn=;
int n;
struct point{
double x;double y;
}p[mxn];
double dist(point a,point b){
return sqrt( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) );
}
struct edge{
int x,y;
double dis;
}e[mxn*mxn];int cnt=;
int cmp(edge a,edge b){
return a.dis<b.dis;
}
int fa[mxn];
void init(){
for(int i=;i<=n;i++)fa[i]=i;
}
int find(int x){
if(fa[x]==x)return x;
return fa[x]=find(fa[x]);
}
double ans=;
void Kruskal(){
int i,j;
int ti=;
ans=;
for(i=;i<=cnt;i++){
int u=find(e[i].x),v=find(e[i].y);
if(u==v)continue;
ti++;
ans+=e[i].dis;
fa[u]=v;
if(ti==n-)break;
}
return;
}
int main(){
int i,j;
while(scanf("%d",&n)!=EOF){
init();
cnt=;
int u,v,dis;int m;
int i,j;
for(i=;i<=n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
for(i=;i<n;i++)
for(j=i+;j<=n;j++){
e[++cnt]=(edge){i,j,dist(p[i],p[j])};
}
sort(e+,e+cnt+,cmp);
Kruskal();
printf("%.2f\n",ans);
}
return ;
}

POJ2560 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. freckles

    题目描述: In an episode of the Dick Van Dyke show, little Richie connects the freckles on his Dad's back ...

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

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

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

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

  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. 解决Genymotion Error: “Unable to load VirtualBox Engine” on Yosemite. VirtualBox installed

    Mac 环境,输入命令 sudo ln -s /usr/local/bin/VBoxManage /usr/bin/VBoxManage

  2. SQLite - WHERE子句

    SQLite - WHERE子句 SQLite WHERE子句用于指定一个条件同时抓取数据从一个表或多个表. 如果给定的条件满意,意味着true,然后从表中返回特定值.你会使用WHERE子句来筛选记录 ...

  3. KissXML的XPath选取问题

    XMPPFramework用的XML解析库还是大神自己写的KissXML,有些人生下来就是让人仰望的,哎. 进入主题,如下一段XML: <paramsxmlns="namespace& ...

  4. WPF中播放视频音频

    首先要在WPF中播放视频和音频,我们就需要用到MediaElement控件,下面我们示例播放音频和视频. 用MediaElement播放音频: 第一步:将你需要播放的音频(mp3)放在你WPF项目的D ...

  5. Xcode 6 创建 Empty Application

    1.创建一个 Single View Application: 2.删除工程目录下的 Main.storyboard 和 LaunchScreen.xib: 3.打开 Supporting Files ...

  6. ios多线程NSThread

    1.简介: 1.1 iOS有三种多线程编程的技术,分别是: 1..NSThread 2.Cocoa NSOperation (iOS多线程编程之NSOperation和NSOperationQueue ...

  7. ZOJ Monthly, January 2019-Little Sub and Pascal's Triangle

    这个题的话,它每行奇数的个数等于该行行号,如果是0开始的,就该数的二进制中的1的个数,设为k,以它作为次数,2k就是了. #include <stdio.h> int main() { i ...

  8. (38)zabbix中配置snmp监控

    1.首先按照“snmp监控快速配置”文本文档在被监控的主机上安装.配置及启动snmp服务, 具体内容如下: 1).安装snmp yum install net-snmp* -y cp -a /etc/ ...

  9. 一段式fsm

    //1-paragraph method to decribe FSM //Describe state transition, state output, state input condition ...

  10. 我的Python分析成长之路2

    2018-12-29 一.python数据类型: 1.数字 int(整形) float(浮点型) complex(复数型) 2.布尔值(bool)     真或假 True or False 3.字符 ...