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. 经典的算法必须填写 ...
随机推荐
- Lesson2
#ifdef __cplusplus #include <cstdlib> #else #include <stdlib.h> #endif #include <SDL/ ...
- 对于exacoin虚拟币以及其他虚拟币乱象的思考
今天晚上12点正,我帮两个朋友购买exacoin虚拟币,当然我也购买,为了购买我做了充分的准备,包括使用多个浏览器和准备良好的***代理,并转如足量BTC以支持购买,但是通过三天晚上的奋战,让我感觉这 ...
- 快速WCF
初级原理:通得过地址调用接口服务,接口服务调用对应实现方法 援引文章地址:http://www.cnblogs.com/iamlilinfeng/archive/2012/09/25/2700049. ...
- 并查集+思维——Destroying Array
一.题目描述(题目链接) 给定一个序列,按指定的顺序逐一删掉,求连续子序列和的最大值.例如序列1 3 2 5,按3 4 1 2的顺序删除,即依次删除第3个.第4个.第1个.第2个,答案为5 4 3 0 ...
- NYOJ-06-喷水装置(一)
http://acm.nyist.net/JudgeOnline/problem.php?pid=6 喷水装置(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 现有 ...
- github+hexo+themes搭建简易个性主题博客
0x00 install Node.js and git 安装Node.js:http://www.runoob.com/nodejs/nodejs-install-setup.html 安装git ...
- 初涉「带权并查集」&&bzoj3376: [Usaco2004 Open]Cube Stacking 方块游戏
算是挺基础的东西 Description 约翰和贝茜在玩一个方块游戏.编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方柱. 游戏开始后,约翰会给贝茜发出P(1≤P ...
- GIMP如何创建layer masks,创建,删除,禁用,复制mask
这次案例是背景替换,采用创建一个新的layer masks: 前期准备好要处理的图片: 1.创建一个新的图层,选择Layer,点击Mask,选择Add Layer Mask: 根据情况选择合适 ...
- 基于ubuntu 14.04 kvm虚拟化部署
1. 宿主机环境(dell备份服务器) Ubuntu 14.04 LTS 64位 内存:16G 硬盘:2T 2. 确认CPU是否支持硬件虚拟化 root@shwilling:~# egrep -o ' ...
- 如何用纯 CSS 创作一个菱形 loader 动画
效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/eKzjqK 可交互视频教 ...