Problem B

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

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
用最短路径做的(错误)代码:

#include <stdio.h>
#include <math.h>
#include <string.h>

const int maxnum = 105;
const int maxint = 999999;
double dist[maxnum];
double prev[maxnum];
double c[maxnum][maxnum];

double ju(double x1,double x2,double y1,double y2)
{
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

void dijkstra(int n,int v)
{
    bool s[maxnum];
    for(int i=1;i<=n;i++)
    {
        s[i] = 0;
        dist[i] = c[v][i];
    }
    s[v] = 1;
    for(int i = 2; i<=n; i++)
    {
        int u=v;
        double temp = maxint;
        for(int j = 1; j<=n; j++)
        {
            if(!s[j]&&dist[j]<temp)
            {
                temp = dist[j];
                u = j;
            }
        }
        s[u] = 1;
        for(int j = 1; j<=n; j++)
        {
            if(!s[j])
            {
                double newdist = dist[j] + c[u][j];
                if(newdist<c[u][j])
                {
                    dist[j] = newdist;
                }
            }
        }
    }
}

int main()
{
    int n;
    double x[105],y[105];
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%lf%lf",&x[i],&y[i]);
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
            {
                c[i][j] = ju(x[i],x[j],y[i],y[j]);
                c[j][i] = c[i][j];
            }
            c[i][i] = 0;
        }
        dijkstra(n,1);
        printf("%.2lf\n",dist[n]);
    }
}

为什么结果不正确?

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. hdu 1162(最小生成树)

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

  3. HDOJ 1162

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

  4. HDOJ 1301最小生成树的Kruskal算法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 将结点的字符信息处理成点信息即可,代码如下: #include<bits/stdc++.h ...

  5. hdu1162Eddy's picture

    http://acm.hdu.edu.cn/showproblem.php?pid=1162 最小生成树 #include<iostream> #include<stdio.h> ...

  6. HDU 1162 Eddy's picture (最小生成树)(java版)

    Eddy's picture 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 ——每天在线,欢迎留言谈论. 题目大意: 给你N个点,求把这N个点 ...

  7. hdu 1162 Eddy&#39;s picture (Kruskal算法,prim算法,最小生成树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 [题目大意] 给你n个点的坐标,让你找到联通n个点的一种方法.保证联通的线路最短,典型的最小生成 ...

  8. HDU 1162 Eddy's picture (最小生成树 prim)

    题目链接 Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to be ...

  9. (最小生成树)Eddy's picture -- hdu -- 1162

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1162 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

随机推荐

  1. HDOJ/HDU 1242 Rescue(经典BFS深搜-优先队列)

    Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is ...

  2. Android项目开发全程(三)-- 项目的前期搭建、网络请求封装是怎样实现的

    在前两篇博文中已经做了铺垫,下面咱们就可以用前面介绍过的内容开始做一个小项目了(项目中会用到Afinal框架,不会用Afinal的童鞋可以先看一下上一篇博文),正所谓麻雀虽小,五脏俱全,这在里我会尽量 ...

  3. html背景为灰色 不能操作,中间div可以操作

    <container style="position: absolute; top: 0px; left: 0px; width: 0px; height: 0px; z-index: ...

  4. eclipse设置项目发布到tomcat webaap下

    之前用myeclipse,自动deploy到web app下.目前的项目换了eclipse,项目被发布到本地,通过一个链接到tomcat中,很不习惯. 设置的地方很隐晦,在tomcat中,而不是在pr ...

  5. 广州Uber优步司机奖励政策(2月1日~2月7日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  6. HttpWebRequest抓数据遇到的问题

    1.有些网站访问速度慢,而且这个网站的连接数(比如全球内衣,另外对于女生各种什么内衣不懂的也可以上去查看了解哈),因为没有即时的关闭,造成抓取页面数据的时候超时也严重. 解决:把相应的HttpWebR ...

  7. 2016-5-19模拟测试 bzoj3652 bzoj3653 bzoj3654

    T1 description 给定正整数\(n\),定义\(f(x) = \max{y \ \mathrm{xor}\ x}(y<n)\) \(x\)在\([0,n)\)随机取值,求\(f(x) ...

  8. linux-centos挂载新硬盘操作

    类似的文章网上已经有很多,这里是记录重要操作的命令,精简流程 精简后的命令: fdisk -ldf -hfdisk /dev/vdbfdisk -l /dev/vdbmkfs -t ext4 /dev ...

  9. Http(2)

    1.传递的请求参数如何获取 GET方式: 参数放在URI后面 POST方式: 参数放在实体内容中 核心的API: request.getParameter("参数名");  根据参 ...

  10. android考试题

    一.选择题 1. Math.round(11.5)等于多少(    ). Math.round(-11.5) 等于多少(   C  ). A.11 ,-11    B.11 ,-12 C.12 ,-1 ...