题目链接: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. document,element,dom对象api详解

    Document对象: 根元素的访问,也就是HTML标签的访问.使用document.documentElement访问根对象. 使用Document对象查找对象 getElementById():通 ...

  2. idea快捷键操作

    在编写代码的时候直接输入psv就会看到一个psvm的提示,此时点击tab键一个main方法就写好了. psvm 也就是public static void main的首字母. 依次还有在方法体内键入f ...

  3. listBox和pictureBox的使用

    重要属性:pictureBox中SizeMode可以更改图像显示的尺寸大小. using System; using System.Collections.Generic; using System. ...

  4. arp_filter/arp_ignore/rp_filter

    下面这段代码应该是arp_ignore/arp_filter的最好的注脚;在ARP_ignore通过的情况下,我再去判断ARP_filter,这个ARP_filter其实就是为了判断,当数据包再出去的 ...

  5. [C/C++] char data[0](柔性数组)

    转自:http://blog.csdn.net/yby4769250/article/details/7294696 在标准C和C++中0长数组如charArray[0]是不允许使用的,因为这从语义逻 ...

  6. 升级到EFCore2.0

    EF Core 2.0上周已经发布了 文章内容基于vs2017,请大家先安装好vs2017(15.3). 本篇文章主要讲下差异点,跟之前一样的就不再重复了. 文章目录(差异点): 一.新建项目, EF ...

  7. HDU3157:Crazy Circuits——题解

    http://acm.hdu.edu.cn/showproblem.php?pid=3157 题目大意:给一个电路 ,起点为+,终点为-,包括起点终点在内的电元件之间有有下界边,求最小流. ————— ...

  8. POJ1741 tree 【点分治】

    Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 25286   Accepted: 8421 Description ...

  9. 洛谷 P3527 [POI2011]MET-Meteors 解题报告

    P3527 [POI2011]MET-Meteors 题意翻译 \(\tt{Byteotian \ Interstellar \ Union}\)有\(N\)个成员国.现在它发现了一颗新的星球,这颗星 ...

  10. bzoj3157: 国王奇遇记

    emmm...... 直接看题解好了: BZOJ-3157. 国王奇遇记 – Miskcoo's Space O(m)不懂扔掉 总之,给我们另一个处理复杂求和的方法: 找到函数之间的递推公式! 这里用 ...