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 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]。但是其间会有一些平行于y轴的河,你需要架桥。给你每米的修路费,和每米的修桥费,问最少的费用是多少?
题解:
现场的时候看了这题,感觉是2元方程,很难求的感觉。赛后,师兄说是三分求最值。然后学了一下三分,就A了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <cmath>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define exp 1e-7
#define ms(a, b) memset((a), (b), sizeof(a))
//#define LOCAL
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int maxn = +;
const int mod = ;
double n, x, y, c1, c2, riverlen, landlen;
double cut(double hh)
{
return c2*hypot(riverlen, hh) + c1*hypot(landlen, y-hh);
}
int main() {
#ifdef LOCAL
freopen("input.txt" , "r", stdin);
#endif // LOCAL
while(~scanf("%lf%lf%lf%lf%lf", &n, &x, &y, &c1, &c2)){
riverlen = 0.0;
for(int i=;i<n;i++){
double xi, wi;
scanf("%lf%lf", &xi, &wi);
riverlen += wi;
}
landlen = x - riverlen;
double l , r, mid, mmid;
l = ;
r = y;
while( l + exp < r){
mid = ( l + r ) / ;
mmid = (mid + r) / ;
if( cut(mid) <= cut(mmid) )
r = mmid;
else
l = mid;
}
printf("%.2f\n", cut(l));
}
return ;
}
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)到 ...
- 1548: Design road (思维题 做法:三分找极值)
1548: Design road Submit Page Summary Time Limit: 2 Sec Memory Limit: 256 Mb Submitted ...
- csu 1548(三分)
1548: Design road Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 383 Solved: 200[Submit][Status][We ...
- HDU 5144 NPY and shot(物理运动学+三分查找)
NPY and shot Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- Gym 101246J Buoys(三分查找)
http://codeforces.com/gym/101246/problem/J 题意: 给定x轴上的n个点的坐标,按顺序从左到右给出,现在要使得每个点的间距相同,可以移动每个点的坐标,但是不能改 ...
- HDU4355 三分查找
/* * 三分查找 */ #include<cstdio> #include<cmath> #define eps 1e-6 //typedef __int64 LL; i ...
- [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- hdu_2899_Strange fuction(三分查找)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2899 题意:让你解方程 题解:对于只有一个凸或者没有凸的图像,可以直接上三分解决. #include& ...
- HDU 2438 Turn the corner(三分查找)
托一个学弟的福,学了一下他的最简便三分写法,然后找了一道三分的题验证了下,AC了一题,写法确实方便,还是我太弱了,漫漫AC路!各路大神,以后你们有啥好的简便写法可以在博客下方留个言或私信我,谢谢了! ...
随机推荐
- 应用安全-安全设备-Waf系列-软Waf-安全狗(Safedog)
安装 - Linux 下载 http://download.safedog.cn/safedog_linux64.tar.gz wget http://download.safedog.cn/safe ...
- JavaSE编码试题强化练习2
1.编写递归算法程序:一列数的规则如下: 0.1.1.2.3.5.8.13.21.34...... 求数列的第40位数是多少. public class TestRecursion { public ...
- CentOS7 iptables安装及操作
添加规则时的考量点: (1)要实现哪种功能:判断添加在哪张表上: (2)报文流经的路径:判断添加在哪个链上: 链上规则的次序: (1)同类规则(访问同一应用),匹配范围小的放上面: (2)不同类规则( ...
- Python中map和reduce函数??
①从参数方面来讲: map()函数: map()包含两个参数,第一个是参数是一个函数,第二个是序列(列表或元组).其中,函数(即map的第一个参数位置的函数)可以接收一个或多个参数. reduce() ...
- python的cls,self,classmethod,staticmethod
python类里会出现这三个单词,self和cls都可以用别的单词代替,类的方法有三种, 一是通过def定义的 普通的一般的,需要至少传递一个参数,一般用self,这样的方法必须通过一个类的实例去访问 ...
- Spring事务嵌套引发的问题--Transaction rolled back because it has been marked as rollback-only
转载https://blog.csdn.net/f641385712/article/details/80445912 读了两边才找到问题
- VS中发布并调试IIS程序
1.创建本地IIS站点 2.修改配置 .net framework 右击项目属性,服务器修改为本地IIS,并且项目URL修改为相对应的站点即可 .net core 右键属性,进入调试栏新建一个配置 选 ...
- spark cli
Spark SQL CLI Spark1.1增加了Spark SQL CLI和ThriftServer SparkSQL CLI配置 1.创建并配置hive-site.xml 在运行Spark SQL ...
- 使用Tabulator遇到的问题
1.Tabulator好像是不支持ie,按照Tabulator文档引入,打开浏览器总是报缺少文件,换了谷歌果然好了. 2.编辑某一行的数据 代码: //Build Tabulator var tabl ...
- netcore中使用session