CSU 1548 Road And Bridge acm 三分
来源:互联网 发布:自然知彼官方旗舰店 编辑:程序博客网 时间:2024/06/15 13:27
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 100100 501 150 90 250 52030 120
Sample Output
50000.0080100.00
首先将所有的河流都合并在一边,然后在陆地与边上任找一点,计算相应的花费,用三分的方法得到最小的花费
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;
double n, x, y, c1, c2, p[1010][2], sum, m;
double dis(double x1, double y1,double x2,double y2){
double mm = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
return mm;
}
double cal(double mm){
double nn = c2*dis(0, 0, sum, mm)+c1*dis(sum,mm,x,y);
return nn;
}
int main(){
while (cin >> n >> x >> y >> c1 >> c2){
for (int i = 0; i < n; i++){
cin >> p[i][0] >> p[i][1];
}
sum = 0;
for (int i = 0; i < n; i++){
sum += p[i][1];
}
double low = 0, high = y, mid = (low + high) / 2, midmid;
while (low + 1e-6 < high){
mid = (low + high) / 2;
midmid = (mid + high) / 2;
if (cal(mid) < cal(midmid))high = midmid;
else low = mid;
}
cout << fixed << setprecision(2) << cal(mid) << endl;
}
return 0;
}
- CSU 1548 Road And Bridge acm 三分
- csu 1548 Road And Bridge
- [ACM] CSU 1548 Design road (三分)
- [ACM] CSU 1548 Design road (三分)
- csu 1548: Design road(三分)
- 三分 --- CSU 1548: Design road
- [csu oj] 1548: Design road(三分)
- CSU 1548-Design road(三分)
- CSU - 1548 三分找最值
- CSU 1548 (三分)
- CSU - 1548 Design road
- CSU-ACM 1004: Xi and Bo
- Design road (三分)
- ACM-三分搜索
- acm CSU 1111
- CSU 1160-ACM
- CSU 1111-ACM
- CSU-ACM2017暑期训练5-三分 E
- 优化或修改CentOS最大连接数限制
- Linux块设备驱动
- Linux下autoconf和automake使用
- Eclipse全屏调试时,如何屏蔽控制台console弹出骚扰!!!
- Struts2拦截器的使用 (详解)
- CSU 1548 Road And Bridge acm 三分
- [乐意黎原创] java里classpath在引入编译文件路径时加星号(*)引起的错误
- 简单记录平时常用容易混淆的小知识点
- android 开发小贴士1
- 南邮 OJ 1092 圆柱体的表面积
- io类的基本问题1
- 使用ThinkPHP框架快速开发网站(多图)
- 代码规范
- 南邮 OJ 1093 阶乘之和