链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1162

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8303    Accepted Submission(s): 4214

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

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <queue>
#include <algorithm>
using namespace std; const int oo = 0x3f3f3f3f;
const int N = ; struct node
{
double x, y;
}s[N]; int n, vis[N];
double dist[N], G[N][N]; double prim()
{
double ans = ;
for(int i=; i<=n; i++)
dist[i] = G[][i]; memset(vis, , sizeof(vis));
vis[] = ; for(int i=; i<=n; i++)
{
int index=;
double Min=oo;
for(int j=; j<=n; j++)
{
if(!vis[j] && dist[j]<Min)
{
Min = dist[j];
index = j;
}
} if(index==)
continue; vis[index] = ;
ans += Min; for(int j=; j<=n; j++)
{
if(!vis[j] && dist[j] > G[index][j])
{
dist[j] = G[index][j];
}
}
}
return ans;
} int main()
{
while(scanf("%d", &n)!=EOF)
{
for(int i=; i<=n; i++)
scanf("%lf%lf", &s[i].x, &s[i].y); for(int i=; i<=n; i++)
for(int j=; j<=i; j++)
G[i][j] = G[j][i] = sqrt((s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y) ); printf("%.2f\n", prim());
}
return ;
}

(最小生成树)Eddy's picture -- hdu -- 1162的更多相关文章

  1. hdoj 1162 Eddy's picture

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

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

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

  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. hdu 1162 Eddy's picture (最小生成树)

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

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

  6. HDU 1162 Eddy's picture

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

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

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

  8. hdu 1162 Eddy's picture (prim)

    Eddy's pictureTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. hdu 1162(最小生成树)

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

随机推荐

  1. 开始SDK之旅-入门2-集成流程图、轨迹图到系统

    http://bbs.ccflow.org/showtopic-2562.aspx 经测试,基本可用,还需增加 WF/Admin/pub.ascx 首先你得先理解流程图的数据的获取方式,其他的就很容易 ...

  2. android 点击返回键 以及 加载activity 生命周期 记录。。。,一目了然

    简叙 Activity 生命周期及android 返回按钮捕捉   @Override protected void onPostCreate(Bundle savedInstanceState) { ...

  3. LAMP的安装和注意事项

    LAMP--Linux+Apache(httpd)+MySQL+PHP,是常用的web服务器架构,下面接受编译安装的过程,以及出现的错误. 注意事项: 1. 扩展epel源:参照:http://www ...

  4. git grade 版本下载及安装

    Git 2.11.1x64下载 gradle各版本下载地址 1. Git安装与配置 Gradle 用法总结

  5. 在eclipse中使用mybatis-generator自动创建代码

    1.eclipse中安装插件,地址:http://mybatis.googlecode.com/svn/sub-projects/generator/trunk/eclipse/UpdateSite/ ...

  6. Hive文件的存储格式

    hive文件存储格式包括以下几类: TEXTFILE SEQUENCEFILE RCFILE 自定义格式 其中TEXTFILE为默认格式,建表时不指定默认为这个格式,导入数据时会直接把数据文件拷贝到h ...

  7. osx安装启动mysql

    安装mysql 最新版 56 brew install mysql 1 启动报错 ben:~ soul$ which mysql /usr/local/bin/mysql ben:~ soul$ my ...

  8. java 工具类 static

    http://wenwen.sogou.com/z/q526955586.htm 工具类其实就是提供了一些公共的函数,方便其他类去调用,函数都写成static一方面是因为方便,另一方面是工具类的函数是 ...

  9. mybatis 3 -枚举

    定义枚举: public static enum AppStateEnum { Valid("有效"), Virtual("虚拟"), Hide("隐 ...

  10. 串口通信,帧与帧之间的时间间隔问题?9600波特率,帧将各在20ms以上