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. 我的第一个Node web程序

    NodeJS的流行也带来了开发由前端转到全栈,前端不再局限于页面如何展现,用户如何操作,也设计到整个应用的架构以及业务流程. 本篇来简单的通过实例,讲述node中web开发的模式. 参考来自<N ...

  2. 【Moqui业务逻辑翻译系列】Story of Online Retail Company 在线零售公司的故事

    h1. Story of Online Retail Company 在线零售公司的故事 Someone decides to sell a product. [Product Marketer Ma ...

  3. 报课系统APP

    031302307黄丰润 031302343张晓燕 #NABCD模型分析 合理分析需求有助于说服客户,所以我们有如下分析 N(need)--客户需要什么 负责人需要将选课信息和选课表格一起发送给所负责 ...

  4. Oracle创建DBLink的方法

    文章从http://blog.csdn.net/davidhsing/article/details/6408770拷贝过来的 1.如果需要创建全局 DBLink,则需要先确定用户有创建 dblink ...

  5. USACO 3.2 butter 最短路

    堆优化dijkstra /* PROB:butter LANG:C++ */ #include <iostream> #include <cstdio> #include &l ...

  6. Bzoj2440 完全平方数

    Time Limit: 10000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Description 小 X 自幼就很 ...

  7. linux内核数据结构学习总结

    目录 . 进程相关数据结构 ) struct task_struct ) struct cred ) struct pid_link ) struct pid ) struct signal_stru ...

  8. MySql与Java的时间类型

    MySql的时间类型有          Java中与之对应的时间类型date                                           java.sql.DateDatet ...

  9. CF Gym 100685E Epic Fail of a Genie

    传送门 E. Epic Fail of a Genie time limit per test 0.5 seconds memory limit per test 64 megabytes input ...

  10. Laravel 5 中的配置

    介绍 Laravel 的所有的配置文件都放在了 config 这个目录的下面.每个选项都有介绍. config├── app.php├── auth.php├── cache.php├── compi ...