csu 1548(三分)
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(三分)的更多相关文章
- 三分 --- CSU 1548: Design road
Design road Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548 Mean: 目的:从(0,0)到 ...
- CSU 1548 Design road(三分查找)
题目链接:https://cn.vjudge.net/problem/142542/origin Description You need to design road from (0, 0) to ...
- csu 1947 三分
题意: 长者对小明施加了膜法,使得小明每天起床就像马丁的早晨一样. 今天小明早上6点40醒来后发现自己变成了一名高中生,这时马上就要做早操了,小明连忙爬起来 他看到操场密密麻麻的人,突然灵光一闪想到了 ...
- 1548: Design road (思维题 做法:三分找极值)
1548: Design road Submit Page Summary Time Limit: 2 Sec Memory Limit: 256 Mb Submitted ...
- CSU训练分类
√√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 ...
- hdu3714 三分找最值
Error Curves Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- BZOJ 1857 传送带 (三分套三分)
在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R.现在lxhgww想从 ...
- hdu 4717(三分求极值)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 思路:三分时间求极小值. #include <iostream> #include ...
- HDU2438 数学+三分
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
随机推荐
- 洛谷 P3398 仓鼠找sugar 解题报告
P3398 仓鼠找sugar 题目描述 小仓鼠的和他的基(mei)友(zi)sugar住在地下洞穴中,每个节点的编号为1~n.地下洞穴是一个树形结构.这一天小仓鼠打算从从他的卧室(a)到餐厅(b),而 ...
- Linux之Json20160705
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.JSON采用完全独立于语言的文本格式,这些特性使JSON成为理想的数据交换语言.易于人阅读和编写,同时也易 ...
- C# 利用mysql.data 在mysql中创建数据库及数据表
C# 利用mysql.data 在mysql中创建数据库及数据表 using System; using System.Collections.Generic; using System.Linq; ...
- OD常见指令和快捷键
声明: 1.本表来自各论坛.博客,欢迎补充讨论 指令 解释 OD汇编指令 NOP 无操作 PUSH 将数据压如堆栈中 POP 出栈(与PUSH相反) PUSHAD 所有通用寄存器的内容按一定顺序压 ...
- C11工具类:字符转换
1.数值类型和字符串转换 1.1 数值转换为字符 std::string to_string(int value); std::string to_string(long value); std::s ...
- Ubuntu 14.04 安装Visual studio Code
上一篇简单介绍了Ubuntu 14.04上如何创建.运行 hello world 程序. 这篇介绍Ubuntu 14.04如何安装Visual studio Code. 网上推荐的有通过Ubuntu ...
- Mock InjectMocks ( @Mock 和 @InjectMocks )区别
之前一直对这两个注解的区别不是很明白. 搜到过一篇博客园的文章举例说明了代码行为的区别.后来在stackoverflow上看到一个问答简单明了的解释了这两个注解在定义上的区别: 在此翻译记录一下: / ...
- 【BZOJ】2125: 最短路 圆方树(静态仙人掌)
[题意]给定带边权仙人掌图,Q次询问两点间最短距离.n,m,Q<=10000 [算法]圆方树处理仙人掌问题 [题解]树上的两点间最短路问题,常用倍增求LCA解决,考虑扩展到仙人掌图. 先对仙人掌 ...
- 浮动&定位
本文地址:http://www.cnblogs.com/veinyin/p/7606652.html 浮动和定位能够让我们把一些元素放到理想的位置,当然,相比之下 float 只能浮动到左边或右边, ...
- SaltStack 使用笔记
centos 7安装yum -y install epel-releaseyum clean allyum makecacheyum -y install salt-minionsed -i 's/# ...