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;
    }
  • 相关阅读:
    3-百度网盘视频在线倍速播放
    16-算法训练 数字三角形
    【2018ACM/ICPC网络赛】徐州赛区
    【python】collections的使用
    【python】遇到的错误
    【2018ACM/ICPC网络赛】沈阳赛区
    【csp】2018-3
    【python】快速排序
    【csp】2017-12
    【校OJ】选网线
  • 原文地址:https://www.cnblogs.com/zlyblog/p/3036464.html
Copyright © 2011-2022 走看看