Test instructions: Give you the starting point (0,0), the end (x, y), there are many rivers in the middle, build bridges above the river to spend C1, on the land to build roads to spend C2, ask you the minimum cost is how much.
Problem-Solving ideas: We know that when we think about it, we can move the river all the way to the side, so we just need three points.
Problem Solving Code:
1 //File name:b.cpp2 //Author:darkdream3 //Created time:2015 March 28 Saturday 13:26 39 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long - - using namespacestd; - intn, x, y, c1,c2; - intTsum; in Doubleans; - DoubleDisDoubleX1,DoubleY1,DoubleX2,Doubley2) to { + returnsqrt ((x1-x2) * (X1-X2) + (y1-y2) * (y1-y2)); - } the voidFenDoubleLow,DoubleHigh ) * { $ DoubleMID1 = low + (high-low) *1/3; Panax Notoginseng DoubleMid2 = low + (high-low) *2/3; - DoubleAnsmid1 =dis (0,0, tsum,mid1) *c2 + DIS (tsum,mid1,x,y) *C1; the DoubleAnsmid2 =dis (0,0, tsum,mid2) *c2 + DIS (tsum,mid2,x,y) *C1; + if(Fabs (ANSMID2-ANSMID1) < 1e-6) A { theAns =Ansmid2; + return; - } $ if(Ansmid1 <Ansmid2) $ Fen (LOW,MID2); - ElseFen (mid1,high); - } the intMain () { - while(SCANF ("%d %d%d%d%d", &N,&X,&Y,&C1,&C2)! =EOF)Wuyi { the inttx, Ty; -Tsum =0 ; Wu for(inti =1; i<= N; i++) - { Aboutscanf"%d%d",&tx,&ty); $Tsum + =Ty; - } -Fen0, y); -printf"%.2f\n", ans); A } + return 0; the}View Code
Hunan Multi-School Tournament (2015.03.28) Bdesign Road