F. Two Points
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There are two points (x1, y1) and (x2, y2) on the plane. They move with the velocities (vx1, vy1) and (vx2, vy2). Find the minimal distance between them ever in future.

Input

The first line contains four space-separated integers x1, y1, x2, y2 ( - 104 ≤ x1,  y1,  x2,  y2 ≤ 104) — the coordinates of the points.

The second line contains four space-separated integers vx1, vy1, vx2, vy2 ( - 104 ≤ vx1,  vy1,  vx2,  vy2 ≤ 104) — the velocities of the points.

Output

Output a real number d — the minimal distance between the points. Absolute or relative error of the answer should be less than 10 - 6.

Examples
Input
1 1 2 2
0 0 -1 0
Output
1.000000000000000
Input
1 1 2 2
0 0 1 0
Output
1.414213562373095

题意:给你两个点 以及这两个点的x,y两个方向的速度 问运动过程中两个点间的最小距离

题解:第一次三分处理 类比二分 二分是针对单调函数的数值确定
三分不仅适用于单调函数,而且适用于凸函数
运动的两点间的距离的图像是不确定的 三分处理..
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
double x1,x2,y1,y2;
double vx1,vx2,vy1,vy2;
double f(double t)
{
double xx1,xx2,yy1,yy2;
xx1=x1+t*vx1;
xx2=x2+t*vx2;
yy1=y1+t*vy1;
yy2=y2+t*vy2;
return sqrt((xx1-xx2)*(xx1-xx2)+(yy1-yy2)*(yy1-yy2));
}
int main()
{
scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
scanf("%lf %lf %lf %lf",&vx1,&vy1,&vx2,&vy2);
double l=,r=1e9,m1,m2;
for(int i=;i<;i++)
{
m1=l+(r-l)/;
m2=r-(r-l)/;
if(f(m1)<f(m2))
r=m2;
else
l=m1;
}
printf("%f\n",f(l));
return ;
}

最新文章

  1. python 通用 修饰器
  2. ACM/ICPC 之 DFS范例(ZOJ2412-ZOJ1008)
  3. CMWAP CMWAP是手机上网使用的接入点的名称
  4. Android:单元测试Junit的配置
  5. 【转】 ARM Linux 3.x的设备树(Device Tree)
  6. .net中Web.config文件的基本原理及相关设置
  7. 【转】树莓派学习笔记——I2C Tools 学习笔记
  8. docker对cpu使用及在kubernetes中的应用
  9. Adobe系列软件下载地址
  10. 调用bios喇叭发声
  11. sql选择
  12. [转] Vue + Webpack 组件式开发(练习环境)
  13. Linux启动顺序、运行级别及开机启动
  14. [C#]List的Sort()、Find()、FindAll()、Exist()的使用方法举例
  15. CF932F Escape Through Leaf 斜率优化、启发式合并
  16. jquery.validate 验证记录
  17. JAVA基础知识总结:十六
  18. django1.10使用本地静态文件
  19. 51Nod1053 最大M子段和V2 二分+DP
  20. python 操作excel格式化及outlook正文,发送邮件

热门文章

  1. 操作表单 -------JavaScrip
  2. 手写promise
  3. WireShark抓包命令
  4. Linux产生随机数的几种方法
  5. thinkphp 3.2.3 - Think.class.php 解析
  6. 最全的PHP函数详解
  7. JZOJ 4307. 喝喝喝
  8. 大数据小项目之电视收视率企业项目08--》MapReduce编写之Wordcount
  9. python中生成器对象和return 还有循环的区别
  10. I miss you, Jenny【我想念你,jenny】