Hdu4081qin Shi Huang ' s national Road System sub-niche into a tree

Source: Internet
Author: User

Given the coordinates of each point and the amount of its population, find a spanning tree, which has a side cost of 0//ask A/b for the maximum value, a the sum of the two points connected by this edge//b the sum of the lengths of the edges other than this edge//first find the smallest spanning tree, then enumerate all the edges, If this edge is the edge of the smallest spanning tree,//directly calculates a A/(Sum-edge), if not, then this edge adds a//ring on the smallest spanning tree, removing the longest edge in the ring remains a tree,//with dp[u][v] represents the size of the longest side that passes through the unique path from U to V in the smallest spanning tree//dp[u][V[i]] = dp[V[i]][u]= Max (map[F[u]][u], dp[F[u]][v[i]]);#include <cstdio>#include <cstring>#include <iostream>#include <cmath>using namespace std; const int MAXN = 1010; const int inf = 0x3f3f3f3f;d ouble dp[MAXN][MAXN];d ouble map[MAXN][MAXN];d ouble X[MAXN], Y[MAXN], P[MAXN]; int F[MAXN]; int VIS[MAXN]; int V[MAXN];d ouble DIS[MAXN]; int n;d ouble Prim () {int len = 0;memset (Vis, 0, sizeof (VIS));memset (DP, 0, sizeof (DP));for (int i = 2;i <=n; i++)dis[i] = inf;dis[1] = 0; F[1] = 1;V[++len] = 1;double ans = 0;While (1)    {double mi = inf; int u;for (int i = 1;i <= n;i++)if (!vis[i]&&dis[i] < mi)mi = dis[u = i];if (mi = = inf) break;Vis[u] = 1;ans + = mi;for (int i = 1;i <= len; i++)Dp[u][v[i]] = dp[v[i]][u]= max (Map[f[u]][u], dp[f[u]][v[i]);V[++len] = u;for (int i = 1;i <= n;i++)if (!vis[i] && map[u][i] < dis[i])        {Dis[i] = map[u][i];f[i] = u;        }    }return ans;}int Main () {//freopen ("In.txt", "R", stdin);int t;scanf ("%d", &t);While (t--)    {scanf ("%d", &n);for (int i = 1;i <= n;i++)        {scanf ("%lf%lf%lf", &x[i], &y[i], &p[i]);For (int j = 1;j <= i;j++)Map[i][j] = map[j][i] = sqrt ((x[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (Y[i]-y[j ]));        }Double sum = Prim ();double ans = 0;for (int i = 1;i <= n;i++)For (int j = 1; j < I; j + +)ans = max (ans, (p[i] + p[j])/(Sum-dp[i][j]));printf ("%.2lf\n", ans);    }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdu4081qin Shi Huang ' s national Road System sub-niche into a tree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.