Test Instructions:Link
Method:0-1 Fractional Planning
parsing:This is the hole that was not filled before, now come to pits. This problem test instructions is n three-dimensional coordinate system point, any two points can be connected to the edge, each side of the cost is two points in the Xoy coordinate system Euclidean distance, each edge of the income is two points of the absolute value of the z difference. N points are connected to a tree in order to minimize the cost of income. That is to ask for the most profit than to spend. A look at the things you can consider 0-1 score planning? So two points that L, and then each side of the get-l*cost is the new weight of each side, because to take the largest n-1 bar, so on the MST, but this is n^2 side, kruscal Word is n^2logn^2*log (two points) should be T dead. So the dense map is prim. It's spicy every time you take a value.
Code:
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 1010#define EPS 1e-6#define INF 0x3f3f3f3fusing namespace STD;intNDoubleTop,bot;structpoint{DoubleX, Y, Z;} Pt[n];structline{intx, y;DoubleGet,cost,l;} L[n*n];intCMP (line A,line b) {returna.l>b.l; }DoubleThedis[n];intTheclo[n];DoubleFunction[n][n];DoubleGet[n][n];DoubleCost[n][n];DoublePrimintu) {Doubleret=0; for(intI=1; i<=n;i++) {if(i==u) thedis[i]=-1, theclo[i]=-1;ElseThedis[i]=function[u][i],theclo[i]=u; } for(intI=1; i<n;i++) {Doubleval=-10000000;intNo for(intj=1; j<=n;j++) {if(theclo[j]!=-1&&thedis[j]>val) Val=thedis[j],no=j; } Ret+=thedis[no]; Top+=get[theclo[no]][no]; Bot+=cost[theclo[no]][no]; theclo[no]=-1; for(intj=1; j<=n;j++) {if(theclo[j]!=-1&&FUNCTION[NO][J]>THEDIS[J]) Thedis[j]=function[no][j],theclo[j]=no; } }returnRET;}intMain () { while(~scanf("%d", &n)) {if(n==0) Break; for(intI=1; i<=n;i++)scanf("%LF%LF%LF", &pt[i].x,&pt[i].y,&pt[i].z);intlinetot=0;DoubleL=0, r=0; for(intI=1; i<=n;i++) { for(intj=1; j<=n;j++) {if(I==J)Continue; cost[i][j]=fabs(PT[I].Z-PT[J].Z); get[i][j]=sqrt((pt[i].x-pt[j].x) * (pt[i].x-pt[j].x) + (PT[I].Y-PT[J].Y) * (PT[I].Y-PT[J].Y)); R=max (R,get[i][j]/cost[i][j]); } }Doubleans=0; while(r-l>eps) {DoubleMid= (L+R)/2.0; for(intI=1; i<=n;i++) { for(intj=1; j<=n;j++) {if(I==J)Continue; FUNCTION[I][J]=GET[I][J]-MID*COST[I][J]; }} top=0, bot=0;DoubleRet=prim (1);if(ret-eps>=0) Ans=max (Ans,top/bot), l=mid+eps;ElseR=mid-eps; }printf("%.3lf\n",1.0/ans); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 2728 Desert King 0-1 score Planning