Eddy's picture

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 28   Accepted Submission(s) : 17

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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

这道题也是非常easy的最短路径问题

代码:

#include<stdio.h>

#include<string.h>

#include<math.h>

#define INF 1 << 30

double a[101] , b[101] , map[101][101] ;

double dis[101] ;

int used[101] ;

void prim(int n)

{

 int c = 0 ;

 int i = 0 , j = 0 ;

 double sum = 0 ;

 dis[1] = 0 ;

 for(i = 1 ; i <= n ; i++)

 {

  double min = INF ;

  c = 0 ;

  for(j = 1 ; j <= n ; j++)

  {

         if(!used[j] && dis[j] < min)

   {

    min = dis[j] ;

    c =j ;

   }

  }

  used[c] = 1 ;

  for(j  = 1 ; j <= n ; j++ )

  {

   if(!used[j] && dis[j] > map[c][j])

    dis[j] = map[c][j] ;

  }

 }

 

 for(i = 1 ; i <= n ; i++)

  sum += dis[i] ;

 printf("%.2lf\n",sum);

}

int main()

{

 int n = 0 ;

 while(~scanf("%d",&n))

 {

  memset(a , 0 , sizeof( a ) ) ;

  memset(b , 0 , sizeof( b ) ) ;

  int i = 0 , j = 0 ;

  for(i = 1 ; i <= n ; i++)

  {

   for(j = 1 ; j <= n ; j++)

       map[i][j] = INF ;

   dis[i] = INF ;

   used[i] = 0 ;

  }

  for(i = 1 ; i <= n ; i++)

  {

            scanf("%lf%lf" , &a[i] , &b[i] );

  }

  double m = 0 , x = 0;

  for(i = 1 ; i <= n ; i++ )

  {

            for(j = 1 ; j <= n ; j++)

   {

    x = (a[j]-a[i])*(a[j]-a[i])+(b[j]-b[i])*(b[j]-b[i]) ;

    m = sqrt( x ) ;

    map[i][j] = map[j][i] = m ;

   }

  }

  prim( n );

 }

 return 0 ;

}

杭电1162Eddy&#39;s picture的更多相关文章

  1. 杭电--1162--Eddy's picture--并查集

    Eddy's picture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  2. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  3. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  4. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  5. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

  6. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  7. C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~

    暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...

  8. 杭电ACM2076--夹角有多大(题目已修改,注意读题)

    杭电ACM2076--夹角有多大(题目已修改,注意读题) http://acm.hdu.edu.cn/showproblem.php?pid=2076 思路很简单.直接贴代码.过程分析有点耗时间. / ...

  9. 杭电ACM2092--整数解

    杭电ACM2092--整数解    分析 http://acm.hdu.edu.cn/showproblem.php?pid=2092 一个YES,一个Yes.试了10几次..我也是无语了..哪里都不 ...

随机推荐

  1. isset,empty,is_null小知识

    <?php /** 在这项研究开始时,有那么多的人不能很好的运用isset,empty,is_null正确null,false等待值回报值做出正确的推理,在这里,我自己总结通过学习小知识,随后的 ...

  2. [LeetCode290]Word Pattern

    题目: Given a pattern and a string str, find if str follows the same pattern. Here follow means a full ...

  3. Git显示漂亮日志的小技巧

    Git的传统log如下所示,你喜欢吗? 看看下面这个你喜不喜欢?(点击图片看大图) 要做到这样,命令行如下: 1 git log --graph --pretty=format:'%Cred%h%Cr ...

  4. Lua面向对象设计(转)

    首先对于Lua语言,它没有打算被用来进行大型的程序设计,相反,Lua目标定于小型到中型的程序设计,通常是作为大型系统的一部分,所以它只提供了一套精简的元素,很多高级语言的概念都没有.这样Lua就成为了 ...

  5. java提高篇(十二)-----equals()

    equals() 超类Object中有这个equals()方法,该方法主要用于比较两个对象是否相等.该方法的源码如下: public boolean equals(Object obj) { retu ...

  6. c# 用正则表达式在指定的字符串中每隔指定个数的文字插入指定字符串

    public static string AddNewLine(string inString,int num,string addString="\r\n") { return ...

  7. 玩转Web之servlet(一)---怎样创建一个servlet

    Servlet概念:servlet就是用java编写的服务器端的小程序,用来完成下B/S架构(即浏览器和服务器架构)下客户端请求的响应处理. servlet通常在容器中运行Tomcat是常见的serv ...

  8. IOS开发——手动设置屏幕旋转

    在移动开发过程.您可能需要跨越看看你的手机.有可能是所有的接口必须跨越,有可能是一个交叉通过电话,当用户当,你的接口也希望他能跨越.还有可能的是,界面的一部分需要被侧向显示.视情况而定,有不同的方法来 ...

  9. [原] Jenkins Android 自动打包配置(转)

    一.Jenkins自动打包配置 目标:1. 自动打包:2. 自动上传:3. 友好下载 1. Jenkins简介 Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作. 减少重复劳 ...

  10. Android应用公布的准备——生成渠道包

    我们须要使用一个变量标明该app的渠道.通常我们能够在manifest中的application节点下声明.例如以下. <meta-data android:name="CHANNEL ...