Eddy's picture(最小生成树)
Eddy's picture |
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
| Total Submission(s): 228 Accepted Submission(s): 168 |
|
Problem Description
Eddy begins to like painting pictures recently ,he is sure of himself to become a painter.Every day Eddy draws pictures in his small room, and he usually puts out his newest pictures to let his friends appreciate. but the result it can be imagined, the friends are not interested in his picture.Eddy feels very puzzled,in order to change all friends 's view to his technical of painting pictures ,so Eddy creates a problem for the his friends of you.
Problem descriptions as follows: Given you some coordinates pionts on a drawing paper, every point links with the ink with the straight line, causes all points finally to link in the same place. How many distants does your duty discover the shortest length which the ink draws? |
|
Input
The first line contains 0 < n <= 100, the number of point. For each point, a line follows; each following line contains two real numbers indicating the (x,y) coordinates of the point.
Input contains multiple test cases. Process to the end of file. |
|
Output
Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the points.
|
|
Sample Input
3 |
|
Sample Output
3.41 |
|
Author
eddy
|
|
Recommend
JGShining
|
#include<bits/stdc++.h>
#define N 110
using namespace std;
struct node
{
int u,v;
double val;
node(){}
node(int a,int b,double c)
{
u=a;
v=b;
val=c;
}
bool operator <(const node & a) const
{
return val<a.val;
}
};
struct point
{
double x,y;
point(){}
point(double a,double b)
{
x=a;
y=b;
}
};
vector<node>edge;
vector<point>p;
int bin[N];
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int findx(int x)
{
while(bin[x]!=x)
x=bin[x];
return x;
}
int n;
double x,y;
void init()
{
for(int i=;i<=n;i++)
bin[i]=i;
}
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
while(scanf("%d",&n)!=EOF)
{
edge.clear();
p.clear();
init();
for(int i=;i<n;i++)
{
scanf("%lf%lf",&x,&y);
p.push_back(point(x,y));
}
for(int i=;i<p.size();i++)
{
for(int j=i+;j<p.size();j++)
{
edge.push_back(node(i,j,dis(p[i],p[j])));
}
}
double cur=;
sort(edge.begin(),edge.end());
for(int i=;i<edge.size();i++)
{
int fx=findx(edge[i].u);
int fy=findx(edge[i].v);
if(fx!=fy)
{
cur+=edge[i].val;
bin[fy]=fx;
}
}
printf("%.2lf\n",cur);
}
return ;
}
Eddy's picture(最小生成树)的更多相关文章
- HDU 1162 Eddy's picture (最小生成树)(java版)
Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...
- hdu 1162 Eddy's picture (最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu 1162 Eddy's picture(最小生成树算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
- HDUOJ-----(1162)Eddy's picture(最小生成树)
Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu Eddy's picture (最小生成树)
Eddy's picture Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- hdoj 1162 Eddy's picture
并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- HDU 1162 Eddy's picture
坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32 ...
- Eddy's picture(prime+克鲁斯卡尔)
Eddy's picture Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Tota ...
- hdu 1162 Eddy's picture (Kruskal 算法)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...
随机推荐
- ACM学习之路___HDU 1385(带路径保存的 Floyd)
Description These are N cities in Spring country. Between each pair of cities there may be one trans ...
- asp.net core权限模块的快速构建
大部分系统都会有权限模块,别人家系统的权限怎么生成的我不知道,我只知道这样做是可以并且挺好的. 文章中只对asp.net core的部分代码进行说明 呃 记录~,mvc版本自行前往仓库查阅 代码中的一 ...
- linux debian 9 配置postgresSQL数据库
#读者注意:本文可以选择不看解释,直接执行每段的0中的代码 (〇):一些概念(可以跳过直接使用(一)0的代码) 1. 客户端:psql.postgreSQL的命令行客户端程序,在终端输入psql进入p ...
- 聊聊Java语言中的单例
package com.xinke.mybatis.test; public class TestSingleton { private static TestSingleton ts = null; ...
- Python自学笔记-面向对象编程(Mr seven)
类的成员可以分为三大类:字段.方法和属性. 一.字段 字段包括:普通字段和静态字段,他们在定义和使用中有所区别,而最本质的区别是内存中保存的位置不同, 普通字段属于对象 静态字段属于类 二.方法 方法 ...
- Python实战之列表list的详细简单练习2
name_list = ['zhangsan','lisi','wangermazi','xiaotaoqi'] print(name_list) # name_list.append("w ...
- wpf 制作必输项的*标记
直接引用帮助文档上的话吧,以免下次忘记! AdornedElementPlaceholder 类 .NET Framework 3.5 其他版本 此主题尚未评级 - 评价此主题 更新:20 ...
- cocos2dx - shader实现任意动画的残影效果
本节主要讲利用cocos2dx机制实现opengl es shader脚本的绘制 这里先看下最终效果: 这里分别实现了灰度效果及残影的效果. 一.绘制基类 这 ...
- C#使用Xamarin开发可移植移动应用进阶篇(10.综合演练,来一份增删改查CRUD)
前言 系列目录 C#使用Xamarin开发可移植移动应用目录 源码地址:https://github.com/l2999019/DemoApp 可以Star一下,随意 - - 说点什么.. 呃 也有半 ...
- Django中添加富文本编辑器
使用的是CKeditor这个模块 1.安装: pip install django-ckeditor 2.将ckeditor注册到settings.py文件中, 并添加ckeditor的url到你项目 ...