1548: Design road

Time Limit: 2 Sec  Memory Limit: 256 MB
Submit: 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 (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 题意:有一个人要从(0,0)->(x,y),中间有n条河,每条河都有一个宽度和一个起始位置,并且上一条河与下一条河无交点,修一公里路花费 c1 ,一公里河花费 c2,问人从起点到终点的最小费用?
题解:我们将所有的和平移到最右边,那么这里就只要枚举河岸就OK了,单峰极值,三分求解。(0,0)->(X,t)为河,(X,t)->(x,y)为路.花费为 sqrt(X*X+t*t)*c2+sqrt((x-X)*(x-X)+(y-t)*(y-t))*c1
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int n;
double x,y,c1,c2,sum,X;
const double eps = 1e-;
double Calc(double t)
{
return sqrt(X*X+t*t)*c2+sqrt((x-X)*(x-X)+(y-t)*(y-t))*c1;
}
double solve(double MIN,double MAX)
{
double Left, Right;
double mid, midmid;
double mid_value, midmid_value;
Left = MIN;
Right = MAX;
while (Left +eps < Right)
{
mid = (Left + Right) / ;
midmid = (mid + Right) / ;
mid_value = Calc(mid);
midmid_value = Calc(midmid);
if (mid_value <= midmid_value) Right = midmid;
else Left = mid;
}
return Left;
}
int main()
{
while(scanf("%d%lf%lf%lf%lf",&n,&x,&y,&c1,&c2)!=EOF)
{
X = ;
for(int i=; i<=n; i++)
{
double a,b;
scanf("%lf%lf",&a,&b);
X+=b;
}
double k = solve(,y);
printf("%.2lf\n",Calc(k));
}
}

csu 1548(三分)的更多相关文章

  1. 三分 --- CSU 1548: Design road

    Design road Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548 Mean: 目的:从(0,0)到 ...

  2. CSU 1548 Design road(三分查找)

    题目链接:https://cn.vjudge.net/problem/142542/origin Description You need to design road from (0, 0) to ...

  3. csu 1947 三分

    题意: 长者对小明施加了膜法,使得小明每天起床就像马丁的早晨一样. 今天小明早上6点40醒来后发现自己变成了一名高中生,这时马上就要做早操了,小明连忙爬起来 他看到操场密密麻麻的人,突然灵光一闪想到了 ...

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

    1548: Design road Submit Page    Summary    Time Limit: 2 Sec     Memory Limit: 256 Mb     Submitted ...

  5. CSU训练分类

    √√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 ...

  6. hdu3714 三分找最值

    Error Curves Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  7. BZOJ 1857 传送带 (三分套三分)

    在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R.现在lxhgww想从 ...

  8. hdu 4717(三分求极值)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 思路:三分时间求极小值. #include <iostream> #include ...

  9. HDU2438 数学+三分

    Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

随机推荐

  1. 洛谷 U14472 数据结构【比赛】 【差分数组 + 前缀和】

    题目描述 蒟蒻Edt把这个问题交给了你 ---- 一个精通数据结构的大犇,由于是第一题,这个题没那么难.. edt 现在对于题目进行了如下的简化: 最开始的数组每个元素都是0 给出nnn,optopt ...

  2. Linux基础--------centos7 安装python3(yum安装)

    #安装sqlite-devel yum -y install sqlite-devel #安装依赖 yum -y install make zlib zlib-devel gcc-c++ libtoo ...

  3. 图像处理之中值滤波介绍及C实现

    1 中值滤波概述 中值滤波是基于排序统计理论的一种能有效抑制噪声的非线性信号平滑处理技术,它将每一像素点的灰度值设置为该点某邻域窗口内的所有像素点灰度值的中值. 中值滤波的基本原理是把数字图像或数字序 ...

  4. VC++的debug与release版本

    因为在Debug中有ASSERT断言保护,所以要崩溃,而在Release优化中就会删掉ASSERT,所以会出现正常运行. void func() {    char b[2]={0};    strc ...

  5. ASP.NET 使用ajaxupload.js插件出现上传较大文件失败的解决方法

    在网上下载了一个ajaxupload.js插件,用于无刷新上传图片使的,然后就按照demo的例子去运行了一下,上传啊什么的都OK,但是正好上传的示例图片有一个比较大的,4M,5M的样子,然后上传就会报 ...

  6. C#获取Json字符串中的某个值

    问题描述: json数据格式{"resCode":0,"resMag":"aaa","data":[{"par ...

  7. Bash to check SSL cert expired

    Code like this, You can send out a email to notice $ cat urls.txt www.baidu.com $ cat cert_chk.sh #! ...

  8. hdu 2121 Ice_cream’s world II

    Ice_cream’s world II http://acm.hdu.edu.cn/showproblem.php?pid=2121 Time Limit: 3000/1000 MS (Java/O ...

  9. 图论:DFS序

    DFS序可以把树转到区间上再用高级数据结构维护,比树链剖分好理解很多 一个闭区间就是一棵子树 POJ3321 #include<cstdio> ; ; int n,m,id,cnt; in ...

  10. JVM调优总结(6):新一代的垃圾回收算法

    垃圾回收的瓶颈 传统分代垃圾回收方式,已经在一定程度上把垃圾回收给应用带来的负担降到了最小,把应用的吞吐量推到了一个极限.但是他无法解决的一个问题,就是Full GC所带来的应用暂停.在一些对实时性要 ...