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