csu 1548: Design road(三分)

1548: Design road

Time Limit: 2 Sec  Memory Limit:
256 MB

Submit: 243  Solved: 115

[Submit][Status][Web
Board
]

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

HINT

题意:修路:从(0,0)~(x,y),n个数表示有第二行开始有n行表示有n条河,tx是河的起始位置,ty是河的宽度,有水的地方要修桥,而x,y表示修路的端点,C1表示修路每米的花费,C2表示修桥每米的花费,问你最后花费的最少金额!

题解:吧河移到靠 x 处,然后left =0,right =y,三分,求极小值。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#define eps 1e-8

int n;
double x,y,c1,c2,W;

double ff(double ay) {
    return sqrt((x-W)*(x-W)+ay*ay)*c1+sqrt((y-ay)*(y-ay)+W*W)*c2;
}

int main() {
    //freopen("in.txt","r",stdin);
    while(~scanf("%d%lf%lf%lf%lf",&n,&x,&y,&c1,&c2)) {
        double ax,aw;
        W=0;
        for(int i=0; i<n; i++) {
            scanf("%lf%lf",&ax,&aw);
            W+=aw;
        }
        double left=0,right=y*1.0;
        double mid1,mid2;
        for(int i=0; i<100; i++) {
            mid1=(right+left)/2;
            mid2=(left+mid1)/2;
            if(ff(mid1)<ff(mid2)) {
                left=mid2;
            } else {
                right=mid1;
            }
        }
        printf("%.2f\n",ff(left));
    }
    return 0;
}
时间: 2024-08-27 13:10:03

csu 1548: Design road(三分)的相关文章

三分 --- CSU 1548: Design road

Design road Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548 Mean: 目的:从(0,0)到达(x,y).但是在0~x之间有n条平行于y轴的河,每条河位于xi处,无限长,wi宽,并分别给出了建立路和桥每公里的单价 求:到达目标的最小费用. analyse: 比赛的时候一直没想到思路,第二个样列怎么算都算不对,赛后才知道是三分. 首先把所有的桥移到最右端,然后三分枚举路和河的交点. Time

[ACM] CSU 1548 Design road (三分)

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548 第一次接触三分,题意和代码参考的网上的. 题意:修路:从(0,0)~(x,y),n个数表示有第二行开始有n行表示有n条河,tx是河的起始位置,ty是河的宽度,有水的地方要修桥,而x,y表示修路的端点,C1表示修路每米的花费,C2表示修桥每米的花费,问你最后花费的最少金额! 思路:先把有河的地方都和到一起,然后它的宽度就知道了,那么就把高度三分,找花费最小的点 这里三分求的是最小值. 三分法

CSU 1548 Design road(三分查找)

题目链接:https://cn.vjudge.net/problem/142542/origin 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

csu 1548: Design road (三分)

题意:需要从(0,0) 点 到(x,y) 修一段路 其中有n条和y轴平行的河 修路的单位成本c1 修桥的单位成本c2 问最小总成本为多少 思路:把所有河合并 再三分桥的长度 求出最小成本 #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<queu

1548: Design road (思维题 做法:三分找极值)

1548: Design road Submit Page    Summary    Time Limit: 2 Sec     Memory Limit: 256 Mb     Submitted: 450     Solved: 237 Description You need to design road from (0, 0) to (x, y) in plane with the lowest cost. Unfortunately, there are N Rivers betwe

csu 1548(三分)

1548: Design road Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: 383  Solved: 200[Submit][Status][Web Board] 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

湖南多校对抗赛(2015.03.28) B Design road

题意:给你起点(0,0),终点(x,y),中间有很多条河, 在河上面建桥花费c1,在陆地建路花费c2,问你最小花费是多少. 解题思路:我们知道,我们考虑的时候完全可以把河都移动到一边来求,这样只需要三分就行了. 解题代码: 1 // File Name: b.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月28日 星期六 13时26分39秒 4 5 #include<vector> 6 #include<list> 7 #

2018年省赛热身赛第4场

A:CSU 1547: Rectangle (思维题加一点01背包) B:1548: Design road (思维题 做法:三分找极值) C:1549: Navigition Problem (几何计算+模拟 细节较多) D:1550: Simple String (做得少的思维题,两个字符串能否组成另外一个字符串问题) G:1553: Good subsequence (很奇妙的set模拟题,也可以直接暴力) H:1554: SG Value (巧妙的模拟题,也属于思维题) I:1555:

CSU 1728 线形逐步共聚合反应(三分)

题意:给你n个东西,然后每个东西里面a物质各加了ai,然后让你往每个东西里面加等量的b物质,要求这里面 |sum(a)-sum(b)|最大的一个区间的这个值最小,问你b物质应该加多少? 题解:假设b物质加x,让s(i,j)=sigma(a[k]-x)要求的是最小化 max|s(i,j)| (i,j都属于1到n) 光这么看的话基本是没有什么想法的,我就是太蠢,在这里愣了好久不知道怎么做,其实应该进行化简 max|s(i,j)| = max( max( s(i,j) , -s(i,j) ) ) =