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路!各路大神,以后你们有啥好的简便写法可以在博客下方留个言或私信我,谢谢了! ...
随机推荐
- Mysql 免安装版本配置
1. 安装命令 (制定安装目录的my.ini文件) mysqld --install MySQL --defaults-file="C:\mysql-5.7.26-winx64\bin\my ...
- Tensorflow之CNN卷积层池化层padding规则
padding的规则 · padding=‘VALID’时,输出的宽度和高度的计算公式(下图gif为例) 输出宽度:output_width = (in_width-filter_wid ...
- AngularJs——基础小知识(二)
AngularJs的过滤器 1.Currency :过滤器(金额货币格式化)
- raid10 五块硬盘/raid5(三块使用,两块备份)
raid 10五块硬盘 第一步:在虚拟机中在添加五块硬盘 第二步:使用mdadm命令创建RAID10,名称为“/dev/md0/” -C代表创建操作,-v显示创建过程,-a yes检查RAID名称,- ...
- SpringBoot 使用logback
1.添加pom引用 <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback ...
- MySQL学习笔记(上)
在进行SQL注入原理的剖析的时候,对MySQL数据库掌握薄弱,参照菜鸟教程的MySQL教程速刷一遍MySQL 关于MySQL MySQL是最流行的关系型数据库管理系统,在WEB方面MySQL是最好的R ...
- 2019 Multi-University Training Contest 7 - 1006 - Snowy Smile - 线段树
http://acm.hdu.edu.cn/showproblem.php?pid=6638 偷学一波潘哥的二维离散化和线段树维护最大子段和. 思路是枚举上下边界,但是不需要从左到右用最大子段和dp. ...
- Angular 组件通讯方式
(一)父子组件 输入/输出属性 关键词 Input,Output,EventEmitter. 父子组件信息信息,分为 (1)子组件向父组件传递 (2)父组件向子组件传递 (二)模版变量与 @V ...
- asp.net 几种传值方法的分析
本文转自:http://www.cnblogs.com/shengtianlong/archive/2010/08/11/1797608.html ASP.NET页面传值方法的优缺点及适用范围 1. ...
- 07-js数据类型
# JavaScript 基本数据类型 typeof函数获取一个变量的类型: ```angularjs* boolean - 如果变量是 Boolean 类型的* number - 如果变量是 Num ...