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. Jackson中的那些坑

    不符合驼峰规范的变量 “驼峰命名法”请自行百度.简单的来说就是变量的第一个单词以小写字母开始其他单词首字母大写,或者全部单词首字母都大写,分别称为“小驼峰”和“大驼峰” 比如一个符合驼峰规范命名的实体 ...

  2. Yii - 验证和授权(Authentication and Authorization)

    1. 定义身份类 (Defining Identity Class)  为了验证一个用户,我们定义一个有验证逻辑的身份类.这个身份类实现[IUserIdentity] 接口.不同的类可能实现不同的验证 ...

  3. MFC中树控件CTreeCtrl的用法

    树形控件可以用于树形的结构,其中有一个根接点(Root)然后下面有许多子结点,而每个子结点上有允许有一个或多个或没有子结点.MFC中使用CTreeCtrl类来封装树形控件的各种操作.通过调用 BOOL ...

  4. c语言数据处理!

    #include "stdio.h" struct { ]; long nume; ]}; ]; float score; }stur; main() { printf(" ...

  5. 【JAVA - SSM】之MyBatis的ParameterType的使用

    在MyBatis的Mapper.xml文件中,参数的表示方法有两种:一种是使用 "#{XXX}" 的方式表示的,另一种是使用 "${XXX}" 的方式表示的.今 ...

  6. springsecurity4+springboot 实现remember-me 发现springsecurity 的BUG

    前言:现在开发中,记住我这个功能是普遍的,用户不可能每次登录都要输入用户名密码.昨天准备用spring security的记住我功能,各种坑啊,吐血 . 先看下具体实现吧. spring securi ...

  7. Conditionals with Omitted Operands (x ? : y)

    Conditionals with Omitted Operands The middle operand in a conditional expression may be omitted. Th ...

  8. Bootstrap-基于jquery的bootstrap在线文本编辑器插件Summernote

    Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线编辑器.Summernote非常的轻量级,大小只有30KB,支持Safari,Chrome,Firefox.Op ...

  9. FC网络学习笔记01

    1.Fibre Channel 也就是“网状通道”的意思,简称FC,可以称其为FC协议.FC网络或FC互联. 2.像TCP/IP一样,FC协议集同样具备TCP/IP协议集以及以太网中的概念,比如FC交 ...

  10. android_handler(三)

    这篇记录 android 消息机制中,MainThread 向 WorkThread 发送消息.( MainThread → WorkThread ) 步骤: 1.准备looper对象 2.在子线程中 ...