zoukankan      html  css  js  c++  java
  • hdu1162 Eddy's picture

    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
    View Code
    #include<stdio.h>
    #include<math.h>
    #include<string.h>
    int n;
    double map[210][210],a[210];
    int b[210];
    void met()
    {
        int i,t;
        t=1;
        a[t]=0;
        while(b[t]==0)
        {
            b[t]=1;
            for(i=1;i<=n;i++)
                if(b[i]==0&&a[i]>map[t][i])
                    a[i]=map[t][i];
            double min=200000000;
            for(i=1;i<=n;i++)
                if(b[i]==0&&min>a[i])
                {
                    min=a[i];
                    t=i;
                }
        }
    }
    int main()
    {
        int i,j,k;
        double f[210],g[210];
        while(scanf("%d",&n)!=-1)
        {
            for(i=1;i<=n;i++)
                scanf("%lf%lf",&f[i],&g[i]);
            memset(map,9,sizeof(map));
            for(i=1;i<=110;i++)
                a[i]=200000000;
            memset(b,0,sizeof(b));
            double x,y;
            double d;
            for(i=1;i<=n;i++)
            {
                for(j=1;j<=i;j++)
                {
                    x=f[i]-f[j];
                    y=g[i]-g[j];
                    d=sqrt(x*x+y*y);
                    map[i][j]=map[j][i]=d;
                }
            }
            met();
            double sum=0;
            for(i=1;i<=n;i++)
                sum+=a[i];
            printf("%.2f\n",sum);
        }
        return 0;
    }
  • 相关阅读:
    JQuery
    CSS
    函数装饰器
    函数
    模块和运算符
    前端编程基础
    MySQL优化指南-大表优化思路
    Linux命令find讲解
    LeetCode每日题解(0324)
    Kmeans算法的经典优化——mini-batch和Kmeans++
  • 原文地址:https://www.cnblogs.com/zlyblog/p/3036464.html
Copyright © 2011-2022 走看看