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
1.0 1.0
2.0 2.0
2.0 4.0
 
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(最小生成树)的更多相关文章

  1. HDU 1162 Eddy's picture (最小生成树)(java版)

    Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...

  2. hdu 1162 Eddy's picture (最小生成树)

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  3. hdu 1162 Eddy's picture(最小生成树算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 Eddy's picture Time Limit: 2000/1000 MS (Java/Ot ...

  4. HDUOJ-----(1162)Eddy's picture(最小生成树)

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  5. hdu Eddy's picture (最小生成树)

    Eddy's picture Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

  6. hdoj 1162 Eddy's picture

    并查集+最小生成树 Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  7. HDU 1162 Eddy's picture

    坐标之间的距离的方法,prim算法模板. Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32 ...

  8. Eddy's picture(prime+克鲁斯卡尔)

    Eddy's picture Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

  9. 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 ...

随机推荐

  1. program 1 : python codes for login program(登录程序python代码)

    #improt time module for count down puase time import time #set var for loop counting counter=1 #logi ...

  2. 小符号反映大问题,Shell中下划线_与变量的关系。

    之前写过一个根据日期和时间自动命名文件名的时候遇到一个问题. #! /bin/bash read -p "please input the filename:" filename ...

  3. Training little cats poj3735

    Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9299   Accepted: 2 ...

  4. Football 概率DP poj3071

                                                                                                 Footbal ...

  5. 简单Elixir游戏服设计-玩法simple_poker

    上回介绍了玩法,现在编写了玩法的简单建模. 做到现在感觉目前还没有使用umbrella的必要(也许以后会发现必要吧),model 应用完全可以合并到game_server. 代码还在https://g ...

  6. PHP中include与require的特点和区别说明

    引用文件的方法有两种:require 及 include.两种方式提供不同的使用弹性. require 的使用方法如 require("MyRequireFile.php"); . ...

  7. python 多线程和多进程的区别 mutiprocessing theading

    多线程可以共享全局变量,多进程不能.多线程中,所有子线程的进程号相同:多进程中,不同的子进程进程号不同. #!/usr/bin/python # -*- coding:utf-8 -*- import ...

  8. 【实验吧】Once More

    <?php if (isset ($_GET['password'])) { if (ereg ("^[a-zA-Z0-9]+$", $_GET['password']) = ...

  9. hdu5696 区间的价值

    区间的价值 我们定义"区间的价值"为一段区间的最大值*最小值. 一个区间左端点在L,右端点在R,那么该区间的长度为(R-L+1). 现在聪明的杰西想要知道,对于长度为k的区间,最大 ...

  10. nginx的反向代理功能和缓存功能

    html { font-family: sans-serif } body { margin: 0 } article,aside,details,figcaption,figure,footer,h ...