POJ2560 Freckles
| Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %lld & %llu |
Description
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
Output
Sample Input
3
1.0 1.0
2.0 2.0
2.0 4.0
Sample Output
3.41
Source
/*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的更多相关文章
- 10034 - Freckles 克鲁斯克尔最小生成树!~
/* 10034 - Freckles 克鲁斯克尔最小生成树!- */ #include<iostream> #include<cstdio> #include<cmat ...
- poj 2560 Freckles
题目连接 http://poj.org/problem?id=2560 Freckles Description In an episode of the Dick Van Dyke show, li ...
- freckles
题目描述: In an episode of the Dick Van Dyke show, little Richie connects the freckles on his Dad's back ...
- 题目1144:Freckles(最小生成树进阶)
题目链接:http://ac.jobdu.com/problem.php?pid=1144 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- 九度OJ 1144:Freckles(斑点) (最小生成树)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1538 解决:760 题目描述: In an episode of the Dick Van Dyke show, little Richi ...
- 【九度OJ】题目1144:Freckles 解题报告
[九度OJ]题目1144:Freckles 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1144 题目描述: In an ...
- UVA 10034 Freckles 最小生成树
虽然是道普通的最小生成树题目,可还是中间出了不少问题,暴露的一个问题是不够细心,不够熟练.所以这篇博客就当记录一下bug吧. 代码一:kruskal #include<stdio.h> # ...
- uva 10034 Problem A: Freckles
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- POJ 2560 Freckles Prime问题解决算法
这个问题正在寻求最小生成树. 给定节点的坐标,那么我们需要根据各个点之间的这些坐标来计算距离. 除了这是标准的Prime算法的,能源利用Prime基本上,你可以使用Kruskal. 经典的算法必须填写 ...
随机推荐
- Django auth权限
创建超级管理员命令 python manage.py createsuperuser --username hello 检查和校验用户 from django.contrib import auth ...
- python中的循环语句-01
接触python已经一周时间,下面针对这一周python学习的情况做一梳理: 1)单行注释,使用一个#:多行注释,使用三个单引号(或者三个双引号)如: name = input("name: ...
- Jascript原型链以及Object和Function之间的关系
先看一个简单的function变量 function fun1(name) { this.name = name; } console.log("fun1", fun1) 从结果可 ...
- Bootstrap 网格系统(Grid System)实例5
Bootstrap 网格系统(Grid System)实例5:手机,平板电脑,笔记本或台式电脑 <!DOCTYPE html><html><head><met ...
- 如何禁用Visual Studio的Browser Link功能
在Web.Config的AppSetting节点添加<add key="vs:EnableBrowserLink" value="false"/>
- (38)zabbix中配置snmp监控
1.首先按照“snmp监控快速配置”文本文档在被监控的主机上安装.配置及启动snmp服务, 具体内容如下: 1).安装snmp yum install net-snmp* -y cp -a /etc/ ...
- wordpress配置SMTP服务发送邮件(qq邮箱)
wordpress有一个注册功能,填了用户名和邮箱后,会收到一封邮件,邮件里有一个链接,点击该链接可以获得密码和修改密码.但是,最开始,你会发现,等半天都没有收到邮件,再等到猴年马月也不会收到. 但是 ...
- (转)UILabel常用属性
Java代码 收藏代码 #import "ViewController.h" #import <CoreText/CoreText.h> @interface View ...
- JQuery中如何处理键盘事件
背景:比如在页面中,敲击回车键以后,实现登录功能,在之前的Winform开发时,也遇到过处理键盘事件的功能,比如游戏软件中,上下左右的移动等. 代码如下: $(document).keydown(fu ...
- CentOS 7.0:搭建SVN服务器
1. 通过 yum install subversion来安装 2. 提示已经安装.查看svn版本 第二步: 创建svn版本库 第三步: 配置svn信息 2. 配置权限配置文件authz 3. 配置用 ...