782B The Meeting Place Cannot Be Changed(二分)
2024-10-20 16:43:23
链接:http://codeforces.com/problemset/problem/782/B
题意: N个点,需要找到一个点使得每个点到这个点耗时最小,每个点都同时开始,且都拥有自己的速度
题解: 对于一个确定的位置,如果耗时最久的点在右边,则这个位置可以往右靠,否则就往左靠,这样,一个二分的解法就形成了
import java.lang.Math;
import java.util.Scanner; public class CodeForces_403_B {
private static final int N = (int) 6e4 + 10;
static int a[] = new int[N];
static int v[] = new int[N];
static double eps = 1e-6; public static void main(String args[]) {
// System.out.println("dfwaed");
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
for (int i = 0; i < n; i++)
a[i] = sc.nextInt();
for (int i = 0; i < n; i++)
v[i] = sc.nextInt(); double l = 1, r = Double.MAX_VALUE, tmp = 0, tmp1, ans = 0;
int tmp2 = 0;
while (Math.abs(r - l) > eps) { double mid = (l + r) / 2;
tmp = Double.MIN_VALUE;
for (int i = 0; i < n; i++) {
tmp1 = Math.abs(a[i] - mid) / v[i];
if (tmp1 > tmp) {
tmp = tmp1;
tmp2 = i;
}
} if ((double) a[tmp2] > mid) {
l = mid;
ans = tmp;
} else
r = mid;
}
System.out.printf("%.6f\n", ans);
}
sc.close();
}
}
最新文章
- VS 中關於附加到進程中調試 的問題。
- js保留位和取整
- osharp3引入事务后操作结果类别的调整
- windows 中 使用MongoDB
- 转载:奇异值分解(SVD) --- 线性变换几何意义(上)
- java递归简易应用教程
- [LeetCode] 147. Insertion Sort List 解题思路
- mysql分组查询前n条数据
- 用UltraISO制作CentOS U盘安装盘
- 前端日常常用git命令
- JS自学笔记02
- MySQL的show profile(已过时)简介以及该功能在MySQL 5.7中performance_schema中的替代
- Ionic App 启动时报Application Error - The connection to the server was unsuccessful
- python内置模块之unittest测试(五)
- EXCEL 将网络图片地址插入为锁定的图片单元格宏
- lua--clone
- JS数组的赋值
- Android MVP 构架封装
- SQLServer 跨库查询实现方法
- PouchDB:JavaScript同步数据库
热门文章
- 常用开源<;监控软件>;介绍
- POJ 2452 Sticks Problem (暴力或者rmq+二分)
- svg image 图片无法铺满 circle 的问题解决
- MySQL-ProxySQL中间件(二)| Admin Schemas介绍
- Springboot拦截器线上代码失效
- WMI 技术
- 暴力/思维 HDOJ 5386 Cover
- 转 linux shell自定义函数(定义、返回值、变量作用域)介绍
- mysql-installer-web-community-5.7.18.1.msi的安装(图文详解)
- Mysql动态查询