题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162

Eddy's picture

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

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
 
题目大意:用最短的线段,使所有的点连通。也就是最短路的一种应用,不多说,prim就可以解决了~~特别注意是输入多组数据的,否则会wa的!!!
 
 #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
double node[],map[][],Min,n;
const double INF=; double prim()
{
int vis[]= {};
int tm=,m;
double sum=;
vis[tm]=;
node[tm]=;
for (int k=; k<=n; k++)
{
Min=INF;
for (int i=; i<=n; i++)
if (!vis[i])
{
if (node[i]>map[tm][i])
node[i]=map[tm][i];
if (Min>node[i])
{
Min=node[i];
m=i;
}
}
vis[m]=;
tm=m;
sum+=node[m];
}
//for (int i=1; i<=n; i++)
//sum+=node[i];
return sum;
} int main ()
{
double a[],b[];
while (cin>>n)
{
for (int i=; i<=n; i++)
cin>>a[i]>>b[i];
for (int i=; i<=n; i++)
{
node[i]=INF;
for (int j=; j<=n; j++)
map[i][j]=INF;
}
for (int i=; i<=n; i++)
{
for (int j=; j<=n; j++)
{
map[i][j]=map[j][i]=sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]));
}
}
printf ("%.2lf\n",prim());
}
return ;
}

hdu 1162 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 (Kruskal 算法)

    题目连接: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

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

  5. hdu 1162 Eddy's picture (prim)

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

  6. HDU 1162 Eddy's picture (最小生成树 prim)

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  7. HDU 1162 Eddy's picture (最小生成树 普里姆 )

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  8. hdu 1162 Eddy's picture(最小生成树,基础)

    题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<string.h> #include <ma ...

  9. 题解报告:hdu 1162 Eddy's picture

    Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become ...

随机推荐

  1. 实验吧编程题:Hashkill

    原题:6ac66ed89ef9654cf25eb88c21f4ecd0是flag的MD5码,(格式为ctf{XXX_XXXXXXXXXXX_XXXXX})由一个0-1000的数字,下划线,纽约的一个区 ...

  2. IIS安装出现“安装程序无法复制文件CONVLOG.EX_”的解决办法

    重新安装了一次IIS,结果就在重新安装的时候,出现安装程序无法复制文件CONVLOG.EX_,上网找了找资料,是因为secedit.sdb 数据库的问题,既然是因为这个文件的问题,那么我们就可以使用w ...

  3. TScreen 类 - 通过 Screen 更换光标

    //更换窗体或某个控件的光标可以不通过 Screen 对象, 譬如: begin   Self.Cursor := crAppStart;   Panel1.Cursor := crHandPoint ...

  4. MyBatis原理简介

    1.什么是 MyBatis ? MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyB ...

  5. css边框以及其他常用样式

    1. 边框是1像素,实体的,红色的. <!DOCTYPE html> <html lang="en"> <head> <meta char ...

  6. libsvm 用在 婚介数据集中 预测 用户配对

     分类前具备的数据集: 书本第九章数据集(训练集):agesonly.csv和matchmaker.csv. agesonly.csv 格式是: 男年龄,女年龄,是否匹配成功 24,30,1 30,4 ...

  7. Android 常用控件自定义样式RadioButton、CheckBox、ProgressBar、

    一.RadioButton / CheckBox 系统自带的RadioButton/CheckBox的样式,注定满足不了实际运用中的情况,有时候自定义自己的样式:此次把自己中工作学习过程中所学到的东西 ...

  8. HDU3065:病毒侵袭持续中——题解

    http://acm.hdu.edu.cn/showproblem.php?pid=3065 ———————————————————————————— Problem Description 小t非常 ...

  9. 我的ACM参赛故事

    从我接触程序竞赛到现在应该有十多年了,单说ACM竞赛,从第一次非正式参赛到现在也差不多有7年多的样子.有太多的故事,想说的话,却一直没能有机会写下来.一方面是自己忙,一方面也是自己懒.所以很感谢能有人 ...

  10. bzoj4390: [Usaco2015 dec]Max Flow(LCA+树上差分)

    题目大意:给出一棵树,n(n<=5w)个节点,k(k<=10w)次修改,每次给定s和t,把s到t的路径上的点权+1,问k次操作后最大点权. 对于每次修改,给s和t的点权+1,给lca(s, ...