Eddy's picture

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

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水题;
#include<stdio.h>
#include<string.h>
#include<math.h>
double g[][];
double ans;
double min=0xfffff;
void prim(int n)
{
double lowclose[];
int closet[],used[],i,j,k;
memset(used,,sizeof(used));
for(i=;i<=n;i++)
lowclose[i]=g[i][],
closet[i]=;
used[]=;
for(i=;i<n;i++)
{
j=;
min=0xfffff;
for(k=;k<=n;k++)
{
if(lowclose[k]<min&&!used[k])
min=lowclose[k],
j=k;
}
used[j]=;
ans+=g[j][closet[j]];
for(k=;k<=n;k++)
{
if(g[k][j]<lowclose[k]&&!used[k])
lowclose[k]=g[k][j],
closet[k]=j;
}
} }
double func(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
int i,j,n;
double t[][];
while(scanf("%d",&n)!=EOF)
{
ans=0.0;
for(i=;i<=n;i++)
g[i][i]=0xfffff,
scanf("%lf %lf",&t[i][],&t[i][]);
for(i=;i<=n;i++)
{
for(j=+i;j<=n;j++)
{
g[j][i]=g[i][j]=func(t[i][],t[i][],t[j][],t[j][]);
}
}
prim(n);
printf("%.2lf\n",ans);
}
return ;
}

HDOJ 1162的更多相关文章

  1. hdoj 1162 Eddy's picture

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

  2. hdoj (1162) 最小生成树

    Problem B Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Sub ...

  3. 杭电hdoj题目分类

    HDOJ 题目分类 //分类不是绝对的 //"*" 表示好题,需要多次回味 //"?"表示结论是正确的,但还停留在模块阶 段,需要理解,证明. //简单题看到就 ...

  4. HDOJ 题目分类

    HDOJ 题目分类 /* * 一:简单题 */ 1000:    入门用:1001:    用高斯求和公式要防溢出1004:1012:1013:    对9取余好了1017:1021:1027:   ...

  5. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  6. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  7. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  8. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  9. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

随机推荐

  1. [C#]Hosting Process (vshost.exe)

    写在前面 最近在群里,有朋友问起这个vshost.exe进程到底是什么?当时确实不知道是个什么东东,给人的感觉是,经常看到它,就是在启动一个项目的时候,经常看到它,就是没细研究它是啥玩意儿.既然遇到了 ...

  2. 网站开发技巧, 使用byte[]持久化用户个性设置

    场景, 网站用户的个性化配置较多, 而且容易发生增加和改变, 如何在数据库保存是个问题. 为了避免数据库表字段经常变更, 我们设计在表增加一个varbinary(max)字段存储个性化配置. 个性化的 ...

  3. 北京大学信息科学技术学院计算机专业课程大纲选摘--JAVA

  4. beta汇总

    第一天:http://www.cnblogs.com/hxh969012806/p/5034085.html 第二天:http://www.cnblogs.com/zyk150910/p/503783 ...

  5. iOS开发中的错误整理,(百思项目,指示器位置)设置控件尺寸和点坐标,先设置尺寸,再设置点坐标

    之前对控件的尺寸和点的坐标的设置从来都是想到什么写什么,从来没有关心过顺序.然后就有了这次的血的教训!!!!! 下面是错误的截图,先设置的中心点,然后设置的宽度.程序运行就这样了,点别的没有毛病!!! ...

  6. Spring-dispatcherServlet

    对于分析SpringMVC,其实就是遵循Servlet世界里最简单的法则“init-service-destroy”. 对于分析SpringMVC的初始化流程,就是分析DispatcherServle ...

  7. HTTP 方法

    HTTP 方法 两种最常用的 HTTP 方法是:GET 和 POST. 什么是 HTTP? 超文本传输协议(HTTP)的设计目的是保证客户机与服务器之间的通信. HTTP 的工作方式是客户机与服务器之 ...

  8. 【poj1201】 Intervals

    http://poj.org/problem?id=1201 (题目链接) 题意 给出n个区间${[ai,bi]}$,要求选出尽可能少的数,使得每个区间i中至少存在${c[i]}$个数. Soluti ...

  9. HDU 1054 Strategic Game(最小点覆盖+树形dp)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=106048#problem/B 题意:给出一些点相连,找出最小的点数覆盖所有的 ...

  10. cmd批处理常用符号详解

    cmd批处理常用符号详解 作者: 字体:[增加 减小] 类型:转载 我们在批处理编写过程中经常遇到各种特殊符号,很多朋友不是很清楚cmd中特殊符号的含义,这里简单的介绍下,方便需要的朋友   1.@一 ...