(三分)Design road,湖南多校对抗赛

Design road
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB
Total submit users: 9, Accepted users: 9
Problem 13267 : Special judge
Problem description


You need to design road from (0, 0) to (x, y) in plane with the lowest cost. Unfortunately, there are N Rivers between (0, 0) and (x, y).It costs c1 Yuan RMB per meter to build road, and it costs c2 Yuan RMB per meter to build a bridge. All rivers are parallel to the Y axis with infinite length.


Input

There are several test cases.

Each test case contains 5 positive integers N,x,y,c1,c2 in the first line.(N ≤ 1000,1 ≤ x,y≤ 100,000,1 ≤ c1,c2 ≤ 1000).

The following N lines, each line contains 2 positive integer xi, wi ( 1 ≤ i ≤ N ,1 ≤ xi < x, xi-1+wi-1 < xi , xN+wN ≤ x),indicate the i-th river(left bank) locate xi with wi width.

The input will finish with the end of file.


Output

For each the case, your program will output the least cost P on separate line, the P will be to two decimal places .


Sample Input
1 300 400 100 100
100 50
1 150 90 250 520
30 120 
Sample Output
50000.00
80100.00
Judge Tips

——Dr.Wu


Problem Source
HNU Contest 

分析:合并一下所有河流与所有陆地,三分河流与陆地交界线的高度。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = 1005;
typedef long long LL;
const int INF = 0xfffffff;
const double EPS = 1e-8;
double N, x, y, c1, c2;
double River;
double f(double h)
{
    return sqrt(River*River + h*h)*c2 + sqrt((x - River)*(x - River) + (y-h)*(y-h))*c1;
}
double ternary(double L, double R)
{
    while (R - L > EPS)
    {
        double mid1 = L + (R - L) / 3;
        double mid2 = R - (R - L) / 3;
        if (f(mid1) < f(mid2))
            R = mid2;
        else
            L = mid1;
    }
    return f((L + R) / 2);
}
int main()
{
    //freopen("f:\\input.txt", "r", stdin);
    while (~scanf("%lf%lf%lf%lf%lf", &N, &x, &y, &c1, &c2))
    {
        River = 0;
        for (int i = 0; i < N; i++)
        {
            double l, w;
            scanf("%lf%lf", &l, &w);
            River += w;
        }
        double ans = ternary(0, y);
        printf("%.2f\n", ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值