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. Easyui使用记录

    一天就这搞了这几行. 1. if else 可以嵌套: 2. 子页面调用父页面js,需要使用top.父页面js的方法. <script type="text/javascript&qu ...

  2. [转]不再以讹传讹,GET和POST的真正区别

    原文地址:http://www.nowamagic.net/librarys/veda/detail/1919 如果有人问你,GET和POST,有什么区别?你会如何回答? 我的经历 前几天有人问我这个 ...

  3. Spring-事物传播行为

    spring事物的传播属性(7种) REQUIRED(默认) 业务方法需要在一个容器里运行.如果方法运行时,已经处在一个事务中,那么加入到这个事务,否则自己新建一个新的事务. 存在事物,则使用当前事物 ...

  4. log4j2 使用说明

    因近期需要编写J2EE程序,所以简单学习了Log4j2,这里把我学习的一些信息做记录: 1.从HelloWorld开始 参考:http://logging.apache.org/log4j/2.x/m ...

  5. Java的多线程机制系列:(三)synchronized的同步原理

    synchronized关键字是JDK5之实现锁(包括互斥性和可见性)的唯一途径(volatile关键字能保证可见性,但不能保证互斥性,详细参见后文关于vloatile的详述章节),其在字节码上编译为 ...

  6. spring 第一篇(1-1):让java开发变得更简单(下)

    切面(aspects)应用 DI能够让你的软件组件间保持松耦合,而面向切面编程(AOP)能够让你捕获到在整个应用中可重用的组件功能.在软件系统中,AOP通常被定义为提升关注点分离的一个技术.系统由很多 ...

  7. codevs4927 线段树练习5

    题目描述 Description 有n个数和5种操作 add a b c:把区间[a,b]内的所有数都增加c set a b c:把区间[a,b]内的所有数都设为c sum a b:查询区间[a,b] ...

  8. 洛谷P2633 王后万岁

    题目描述 byteland的王后深受百姓爱戴.为了表达他们的爱,国民们打算占领一个新的国家,并以王后的名字命名.这个国家有n座城市.城市之间有双向道路连接,且每两个城市之间有且仅有一条道路.每座城市对 ...

  9. Syntax error, annotations are only available if source level is 1.5

    在项目上右键 -> Properties -> Java Compiler

  10. 轻量级应用开发之(02)UIView

    一 控件 1.屏幕上的所有UI元素都叫做控件(也有叫做视图.组件)比如按钮(UIButton).文本(UILabel)都是控件. 2.控件的共同属性有哪些? 尺寸,位置,背景色 3. 苹果将控件的共同 ...