Design Road
problem ' s Link:
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548
Mean:
Purpose: From (0,0) arrival (x, y). But between the 0~x there are n parallel to the y-axis of the river, each river located in Xi, infinitely long, WI-wide, and respectively, to establish the road and bridge per kilometer unit price
Minimum cost to reach the target.
Analyse:
The game has never thought of thinking, the second kind of column how to calculate the wrong, after the game only know is three points.
First move all the bridges to the far right, then three points to enumerate the intersections of the road and the river.
Time Complexity:o (LOGN)
Source Code:
//Memory Time//1347K 0MS//by:crazyacking//2015-03-30-21.24#include <map>#include<queue>#include<stack>#include<cmath>#include<cstdio>#include<vector>#include<string>#include<cstdlib>#include<cstring>#include<climits>#include<iostream>#include<algorithm>#defineMAXN 1000010#defineLL Long Longusing namespacestd;Doublex,y,c1,c2,sum,xx;DoubleCalcDoublemid) { DoubleRoad_cost=sqrt (Xx*xx+mid*mid) *c1, Bridge_cost=sqrt (sum*sum+ (y-mid) * (Y-MID)) *C2; returnroad_cost+Bridge_cost;}DoubleSolveDoubleLowDoubleHigh ) { DoubleL=low,h=High ; DoubleMid= (L+H)/2, mmid= (mid+h)/2; DoubleCmid=calc (mid), cmmid=Calc (mmid); while(Fabs (Cmmid-cmid) >=1e-Ten) { if(cmid>cmmid) L=mid; Elseh=Mmid; Mid= (l+h)/2, mmid= (mid+h)/2; Cmid=calc (mid), cmmid=Calc (mmid); } returnmin (cmmid,cmid);}intMain () {intN; while(cin>>n>>x>>y>>c1>>C2) {Sum=0.0; DoubleTMP1,TMP2; for(intI=1; i<=n;++i) {cin>>tmp1>>TMP2; Sum+=TMP2; } xx=x-sum; printf ("%.2lf\n", Solve (0.0, y)); } return 0;}
View Code
Three-point---CSU 1548:design Road