zoukankan      html  css  js  c++  java
  • hdu 1162 Eddy's picture (prim)

    Eddy's picture
    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 11970    Accepted Submission(s): 6008

    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

    C/C++:

     1 #include <cmath>
     2 #include <cstdio>
     3 #include <climits>
     4 #include <algorithm>
     5 using namespace std;
     6 
     7 int n;
     8 double my_map[110][110];
     9 
    10 struct node
    11 {
    12     double a, b;
    13 }P[110];
    14 
    15 double my_prim()
    16 {
    17     int my_pos = 1, my_book[110] = {0, 1};
    18     double my_ans = 0.0, my_dis[110] = {0, INT_MAX};
    19     for (int i = 2; i <= n; ++ i)
    20         my_dis[i] = my_map[i][my_pos];
    21 
    22     for (int i = 1; i < n; ++ i)
    23     {
    24         double my_temp = INT_MAX;
    25         for (int j = 1; j <= n; ++ j)
    26         {
    27             if (!my_book[j] && my_dis[j] < my_temp)
    28             {
    29                 my_temp = my_dis[j];
    30                 my_pos = j;
    31             }
    32         }
    33         my_ans += my_temp;
    34         my_book[my_pos] = 1;
    35         for (int j = 1; j <= n; ++ j)
    36         {
    37             if (!my_book[j] && my_dis[j] > my_map[j][my_pos])
    38                 my_dis[j] = my_map[j][my_pos];
    39         }
    40     }
    41     return my_ans;
    42 }
    43 
    44 int main()
    45 {
    46     /**
    47         Date Input Initialize
    48     */
    49     while (~scanf("%d", &n))
    50     {
    51         for (int i = 1; i <= n; ++ i)
    52             scanf("%lf%lf", &P[i].a, &P[i].b);
    53         for (int i = 1; i <= n; ++ i)
    54         {
    55             for (int j = i+1; j <= n; ++ j)
    56             {
    57                 double my_temp_a = (P[i].a - P[j].a) * (P[i].a - P[j].a);
    58                 double my_temp_b = (P[i].b - P[j].b) * (P[i].b - P[j].b);
    59                 double my_temp = sqrt(my_temp_a + my_temp_b);
    60                 my_map[i][j] = my_map[j][i] = my_temp;
    61             }
    62         }
    63         printf("%.2lf
    ", my_prim());
    64     }
    65     return 0;
    66 }
  • 相关阅读:
    DB2 db2move导入导出数据及使用dblook导出表结构DDL
    【转】DB2 BLOB大字段数据通过命令行进行导入导出
    【转】【DataGuard】Oracle 11g物理Data Guard之Snapshot Standby数据库功能
    【转】Oracle 11g R2手动配置EM
    【转】Oracle Database Server 'TNS Listener'远程数据投毒漏洞(CVE-2012-1675)
    【转】ORACLE TNS Listener远程注册投毒(Poison Attack)漏洞
    【转】Oracle 11.2.0.4/12C新特性Valid Node Checking For Registration (VNCR)
    【转】使用 xtrabackup 进行MySQL数据库物理备份
    【转】MySQL-物理备份-Percona XtraBackup 备份原理
    【转】NBU expired Media,Media ID not found in EMM database
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9427752.html
Copyright © 2011-2022 走看看