Three-point---CSU 1548:design Road

Source: Internet
Author: User

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

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.