csu 1548 Road And Bridge
2015-07-30 10:47
344 查看
Road And Bridge
思路:不要管河的位置都移到一边(右)+三分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
//AC代码 #include<cstdio> #include<cmath> int n; double x1,y2,c1,c2,wid,real; double fff(double y) { return c1*sqrt(real*real+y*y)+c2*sqrt(wid*wid+(y2-y)*(y2-y)); } int main() { while(scanf("%d %lf %lf %lf %lf",&n,&x1,&y2,&c1,&c2)!=EOF) { int x,y; double min,mid,midd,max; wid=0; while(n--) { scanf("%d%d",&x,&y); wid+=y; } real=x1-wid; min=0; max=y2; while((max-min)>1e-4) { mid=(min+max)/2; midd=(mid+max)/2; if(fff(mid)<fff(midd)) max=midd; else min=mid; } printf("%.2lf\n",fff(mid)); } return 0; }
相关文章推荐
- HDU 2094 产生冠军(STL 集合set)
- POJ_2260_ErrorCorrection
- 收藏
- 使用velocity.js制作炫酷滚动效果页面
- dicom格式文件 界定标识符的处理
- mysql 单机同版本多实例 mysql55
- 深入理解hash长度扩展攻击
- HDU 1300 POJ 1260 Pearls (DP)
- Java 实现基本的排序算法
- IOS中使用像素位图(CGImageRef)对图片进行处理
- Qt creator 如何支持中文编码(Qt4和Qt5解决方法不同)
- elasticsearch Snapshot 写php shell
- hdu 1205 思路题
- [翻译]Java日志终极指南
- 第三方框架
- 谷歌免费字体----Google Fonts
- 如何在bat文件执行完毕后不自动关闭窗口
- 代码如人
- 图片处理类库 Universal-image-loader 简介
- 在一个界面使用定时器后,退出界面后,一定要记得取消定时器