HDUOJ-----(1162)Eddy's picture(最小生成树)
Eddy's picture
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6821 Accepted Submission(s): 3444
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
Author
eddy
此题数据规模娇小,prim随意处理即合..........
代码:
1 #include<cstdio>
2 #include<cstring>
3 #include<cmath>
4 #include<algorithm>
5 using namespace std;
6 const int inf=0x3f3f3f3f;
7 const int maxn=105;
8 double map[maxn][maxn];
9 double lowc[maxn];
10 bool vis[maxn];
11 struct point{
12
13 double x,y;
14 int id;
15 };
16
17 inline double dista(point a,point b){
18 return sqrt((a.y-b.y)*(a.y-b.y)+(a.x-b.x)*(a.x-b.x));
19 }
20
21 point sac[maxn];
22
23 double prim(int st,int n)
24 {
25 memset(vis,0,sizeof(vis));
26 vis[st]=true;
27 double minc=inf;
28 for(int i=1;i<=n;i++)
29 lowc[i]=map[st][i];
30 int pre=st;
31 double sum=0.0;
32 for(int i=1;i<n;i++){
33 minc=inf;
34 for(int j=1;j<=n;j++)
35 {
36 if(!vis[j]&&minc>lowc[j]){
37 minc=lowc[j];
38 pre=j;
39 }
40 }
41 sum+=minc;
42 vis[pre]=true;
43 for(int j=1;j<=n;j++){
44 if(!vis[j]&&lowc[j]>map[pre][j]){
45 lowc[j]=map[pre][j];
46 }
47 }
48 }
49 return sum;
50 }
51 void work(int n)
52 {
53 for(int i=0;i<n;i++){
54 for(int j=0;j<n;j++){
55 map[i+1][j+1]=map[j+1][i+1]=dista(sac[i],sac[j]);
56 }
57 }
58 }
59 int main(){
60 int n;
61 while(scanf("%d",&n)!=EOF){
62
63 for(int i=0;i<n;i++)
64 {
65 scanf("%lf%lf",&sac[i].x,&sac[i].y);
66 sac[i].id=i+1;
67 }
68 work(n);
69 printf("%.2lfn",prim(1,n));
70 }
71 return 0;
72 }
- Android的UI设计与后台线程交互
- 更强悍的Silverlight: WCF RIA Services
- Java究竟该怎么学?文末有彩蛋!
- python-IDLE清屏和标记行数,其他推荐
- 从0到1:PostCSS 插件开发最佳实践
- VUE 入门基础(4)
- 实例演示Android异步加载图片
- 使用OData协议查询Windows日志
- Android之Notification介绍
- postcss-lazysprite: 一种生成CSS 雪碧图的懒惰姿势
- Activity间中使用Intent传值
- VUE 入门基础(3)
- ASP.NET MVC 2 转换工具
- 使用Sysinternals工具定时休眠Windows Server 2008 R2
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 数据分析:在缓慢变化中寻找跳变——基于缓慢变化维度的用户分群
- 02 Confluent_Kafka权威指南 第二章:安装kafka
- Kafka集群搭建过程(kafka2.5+eagle)
- 07 Confluent_Kafka权威指南 第七章: 构建数据管道
- java中的reference(二): jdk1.8中Reference的源码阅读
- 08 Confluent_Kafka权威指南 第八章:跨集群数据镜像
- java的reference(五): WeakReference的应用之二--InheritableThreadLocal源码分析
- rabbitmq-3.7.7安装过程
- 09 Confluent_Kafka权威指南 第九章:管理kafka集群
- 关于禁止使用Executors创建线程池的分析
- ArrayList源码分析(基于jdk1.8)(一):源码及基本操作
- ArrayList源码分析(基于jdk1.8)(二):subList陷阱
- 【每日一题】31. Next Permutation
- 关于聚合和多线程的处理套路
- Jboss漏洞利用总结