zoukankan      html  css  js  c++  java
  • POJ 2560 Freckles

    Freckles
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 5217   Accepted: 2706

    Description

    In an episode of the Dick Van Dyke show, little Richie connects the freckles on his Dad's back to form a picture of the Liberty Bell. Alas, one of the freckles turns out to be a scar, so his Ripley's engagement falls through.
    Consider Dick's back to be a plane with freckles at various (x,y) locations. Your job is to tell Richie how to connect the dots so as to minimize the amount of ink used. Richie connects the dots by drawing straight lines between pairs, possibly lifting the pen between lines. When Richie is done there must be a sequence of connected lines from any freckle to any other freckle.

    Input

    The first line contains 0 < n <= 100, the number of freckles on Dick's back. For each freckle, a line follows; each following line contains two real numbers indicating the (x,y) coordinates of the freckle.

    Output

    Your program prints a single real number to two decimal places: the minimum total length of ink lines that can connect all the freckles.

    Sample Input

    3
    1.0 1.0
    2.0 2.0
    2.0 4.0
    

    Sample Output

    3.41
    

    Source

    //看了一早上KM算法求最大二分匹配,结果水了一道最小生成树、、、

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #include <cmath>
    #define Y 103
    using namespace std;
    struct node
    {
        double x,y;
    };
    node c[Y];
    double p[Y][Y],Max;
    int N;
    bool b[Y];
    double dis(double &x1,double &y1,double &x2,double &y2)
    {
        return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    }
    void prim()
    {
        int i,j,t;
        for(i=1;i<=N;i++)
          b[i]=0;
        b[1]=1;
        t=N-1;
        double min,s=0;
        while(t--)
        {    min=Max;
            for(i=2;i<=N;i++)
             if(!b[i]&&p[1][i]<min)
             {
                 j=i;
                 min=p[1][i];
             }
             s+=min;
             b[j]=1;
             for(i=2;i<=N;i++)
               if(!b[i]&&p[1][i]>p[j][i])
                 p[1][i]=p[j][i];
        }
        printf("%.2lf\n",s);
    }
    int main()
    {
        while(scanf("%d",&N)!=EOF)
        {
            for(int i=1;i<=N;i++)
             scanf("%lf%lf",&c[i].x,&c[i].y);
             Max=0;
            for(int j=1;j<N;j++)
              for(int k=j+1;k<=N;k++)
              {
                  p[j][k]=dis(c[j].x,c[j].y,c[k].x,c[k].y);
                  p[k][j]=p[j][k];
                  Max=Max>p[j][k]?Max:p[j][k];
              }
            prim();
        }

        return 0;
    }

  • 相关阅读:
    Tkinter之布局管理pack
    Python smtplib,email
    PyAutoGUI (2) 屏幕处理和弹框,输入中文
    键鼠操作自动化库--PyAutoGUI模块(1)
    python----->>删除超过固定天数的日志
    Transformer再下一城!Swin-Unet:首个纯Transformer的医学图像分割网络
    西门子S7-1200 PLC 水箱水位控制程序案例
    【开源】Transformer 在CV领域全面开花:新出跟踪、分割、配准等总结
    Google发布语义分割新数据集!顺带开发个模型屠榜,已被CVPR2021接收
    YOLOv5算什么,这个才是最强!---PP-YOLOv2
  • 原文地址:https://www.cnblogs.com/372465774y/p/2589646.html
Copyright © 2011-2022 走看看