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路!各路大神,以后你们有啥好的简便写法可以在博客下方留个言或私信我,谢谢了! ...
随机推荐
- Java设计模式——建造者模式(创建型模式)
概述 建造者模式也称为生成器模式,是一种对象创建型模式,它可以将复杂对象的建造过程抽象出来(抽象类别),使这个抽象过程的不同实现方法可以构造出不同表现(属性)的对象. 建造者模式意在为重叠构造 ...
- mooc-IDEA 高效定位代码--004
十.IntelliJ IDEA -高效定位代码-精准搜索 1.快速定位类:Navigate->Class... [Ctrl+N] 2.文件:Navigate->File.. [Ct ...
- 四种pop模式介绍
四种pop模式介绍 URL:http://www.hishop.com.cn/ecschool/jd/show_21195.html URL:https://zhidao.baidu.com/ques ...
- 实验报告一&第三周学习总结
一.实验报告 1.打印输出所有的"水仙花数",所谓"水仙花数"是指一个3位数,其中各位数字立方和等于该数本身.例如,153是一个"水仙花数" ...
- Java WebService 参考文档
webservice 基础使用 java 与tomcat使用http://cxshun.iteye.com/blog/1275408 spring mvc中使用https://www.cnblogs. ...
- java高级开发面试总结
Java高级工程师面试题总结及参考答案 (转载)博客原文链接:https://www.cnblogs.com/java1024/p/8594784.html 一.面试题基础总结 1. JVM结构原理. ...
- Python的魔法方法??
就是可以给你的类增加魔力的特殊方法,如果你的对象实现 (重载)了这些方法中的某一个,那么这个方法就会在特殊的情况下被 Python 所调用,你可以定义自己想要的行为,而这一切都是自动发生的. __in ...
- OpenCV-----图像的加载与保存
OpenCV中的图像: 定义:在opencv中图像就是结构化存储数据的信息. 属性:1.宽.高和通道数目 1 print(image.shape) #形状:行(长).列(宽).通道数(深度) 2.像素 ...
- 被我误解的max_connect_errors
第一节 什么是max_connect_errors 一开始接触这个参数的时候,感觉他和max_connections的含义差不多,字面意思简单明了,这个参数的含义是最大连接错误数,翻翻mysql的文 ...
- vue路由定义
router 根据URL分配到对应的处理程序 单应用页面,vue开发中只有一个一面 例如我们在开发移动端的时候,正常情况下底部的tab有四个选项: 首页 home 发现 find 订 ...