Hunan Multi-School Tournament (2015.03.28) Bdesign Road

Source: Internet
Author: User

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", &AMP;N,&AMP;X,&AMP;Y,&AMP;C1,&AMP;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

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.