# "Earthquake, 2001 Open" 0-1 score Planning

Source: Internet
Author: User

71 Cow Construction Team
an earthquake destroyed John's homeland, and strong John was determined to rebuild his homeland. John had repaired N pastures, and he needed to
fix some roads to connect them together. As it happens, cows have recently set up a team that specializes in road repair. and
However, the cows are financially savvy, and if they are not profitable, they will not do it.
John and the cows reached an agreement, John paid the cow F yuan, the cow is responsible for road repair, but do not have to fix all roads, just to ensure that
all pastures can be connected. The path to be repaired by the cows is M , and the section I road is connected to the pasture of the U i and the first V i ,
repair requires T i minute, expense cost is C i. There is always a road repair scheme that ensures connectivity to all pastures. The cows were concerned
the rate of earning, that is, the ratio of total profit to total construction time. Please help the cows choose which roads to repair in order to keep them in the unit time
profit in the biggest?
Input Format
? The first line: three integers n, M and F, 1 n 1 /c9>10000 , 1 F 2 x 109
? The second line to the M + 1 line: The i + 1 line has four integers U i, V i, C i and T i, 1 U i , V i N, 1 C i , T i
2 x 109
output Format
? A single floating-point number: Represents the maximum earning speed of the construction team and retains four decimal places in rounding method if the item is a
loss, output 0.0000
Sample Input
5 5
1 2 5
1 3 5
1 4 5
1 5 5
2 3 1
Sample Output
1.0625
explain
Fix the last four roads, the total cost is 83, the sum of time
is 16, so the profit per unit time is ( (/16) =
1 . 0625

Analysis

Because it is a 0-1-score plan, write again.

Actually, it's a two-point?

Two-part answer mid, i.e. requirements [F-sigma (Ci)]/sigma (Ti) >=mid

is F>=sigma (Ci+mid*ti)

On the right as small as possible is more likely to be established, with a minimum of 1 spanning tree krustal.

Well

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <algorithm>6#include <queue>7#include <cmath>8 using namespacestd;9 #defineMAXN 410Ten #defineMAXM 10010 One  A structnode - { -     intx,y,a,b; the     DoubleC; -}t[maxm*2]; -  - intfa[maxn],n,m; + DoubleF; -  + BOOLCMP (node X,node y) {returnx.c<y.c;} A  at intFFAintx) - { -     if(fa[x]!=x)returnFFA (Fa[x]); -     returnFa[x]; - } -  in BOOLCheckDoublex) - { to      for(intI=1; i<=m;i++) t[i].c=t[i].a+x*t[i].b; +Sort (t+1, t+1+m,cmp); -     Doublesum=0;intCnt=0; the      for(intI=1; i<=n;i++) fa[i]=i; *      for(intI=1; i<=m;i++) \$     {Panax Notoginseng         if(FFA (t[i].x)! =FFA (T[I].Y)) -         { theFa[ffa (t[i].x)]=FFA (T[I].Y); +cnt++; Asum+=t[i].c; the         } +         if(cnt==n-1) Break; -     } \$     return(cnt==n-1) && (f>=sum); \$ } -  - voidFfind (DoubleLDoubleR) the { -      while(r-l>0.000001)Wuyi     { the         DoubleMid= (L+R)/2; -         if(Check (mid)) l=mid; Wu         ElseR=mid; -     } Aboutprintf"%.4lf\n", L); \$ } -  - intMain () - { A     Doublesm=0; +scanf"%D%D%LF",&n,&m,&f); the      for(intI=1; i<=m;i++) -     { \$scanf"%d%d%d%d",&t[i].x,&t[i].y,&t[i].a,&t[i].b); thesm+=t[i].a; the     } theFfind (0, SM); the     return 0; -}
OwO

2016-10-31 20:09:07

"Earthquake, 2001 Open" 0-1 score Planning

Related Keywords:

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.