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 ;
}

IX Samara Regional Intercollegiate Programming Contest F 三分的更多相关文章

  1. Codeforces Gym100971 F.Two Points (IX Samara Regional Intercollegiate Programming Contest Russia, Samara, March 13)

    这个题直接推公式就可以. 就是解一元二次方程,用高中学的公式,函数开口向上,求最大值为(4ac-b*b)/4a. 这个题推出来一元二次方程,然后将最大值的公式化简一下.公式很好推. 这个题有疑问,in ...

  2. Gym100971B Gym100971C Gym100971F Gym100971G Gym100971K Gym100971L(都是好写的题。。。) IX Samara Regional Intercollegiate Programming Contest Russia, Samara, March 13, 2016

    昨天训练打的Gym,今天写题解. Gym100971B 这个题就是输出的时候有点小问题,其他的都很简单. 总之,emnnn,简单题. 代码: #include<iostream> #inc ...

  3. Codeforces Gym100971 L.Chess Match (IX Samara Regional Intercollegiate Programming Contest Russia, Samara, March 13)

    这个题就是两个队,看最多能赢的个数,然后比较一下,看两个队是都能赢彼此,还是只有一个队赢的可能性最大.表达能力不好,意思差不多... 和田忌赛马有点像,emnnn,嗯. 代码: 1 #include& ...

  4. Codeforces Gym100971 K.Palindromization-回文串 (IX Samara Regional Intercollegiate Programming Contest Russia, Samara, March 13)

    这个题就是从字符串中删除一个字符,然后剩下的是回文串. 我写的代码虽然长得好看,但是循环里面的比较条件容易想错,太智障了... 一开始写的是计数比较,但是有的时候下标相同的也比较了,为了简单一些,直接 ...

  5. Codeforces Gym100971 G.Repair-思维题(切矩形板子) (IX Samara Regional Intercollegiate Programming Contest Russia, Samara, March 13)

    这个题就是一块大板子,问你能不能切成两块要求的长宽的两块板子,一开始是按切板子想的,感觉有点麻烦. 直接反过来想,把两块要求的板子拼起来,填成一个大板子,看填出来的这个板子和题目给的板子比较,小于等于 ...

  6. Codeforces Gym100971 C.Triangles-组三角形 (IX Samara Regional Intercollegiate Programming Contest Russia, Samara, March 13)

    这个题就是组三角形,从给出的数组里任选两个和未知的边组三角形. 任意两边之和大于第三边,记住这个就可以了. 代码: 1 #include<cstdio> 2 #include<cst ...

  7. Codeforces Gym100971 B.Derangement (IX Samara Regional Intercollegiate Programming Contest Russia, Samara, March 13)

    昨天训练打的Gym,今天写题解. 这个题就是输出的时候有点小问题,其他的都很简单. 代码: #include<iostream> #include<cstring> #incl ...

  8. 2017, X Samara Regional Intercollegiate Programming Contest 题解

    [题目链接] A - Streets of Working Lanterns - 2 首先将每一个括号匹配串进行一次缩减,即串内能匹配掉的就匹配掉,每个串会变成连续的$y$个右括号+连续$z$个左括号 ...

  9. X Samara Regional Intercollegiate Programming Contest DIV2

    http://codeforces.com/gym/101341 其实我觉得这份题很不错的,虽然是div2,但是感觉对我挺有帮助(我比较垃圾0.0),还没补完(做的时候一直蒙逼,要补很多题)先写一点点 ...

随机推荐

  1. bootstrap table加载数据

    //html <table id="dailyDevTable"></table> //js $(function () { initTable(); }) ...

  2. 简单的Maven+SpringMVC

    一.SpringMVC非注解编程 1:修改pom.xml文件(相当于非Maven项目的导入jar包) <!-- https://mvnrepository.com/artifact/org.sp ...

  3. node 发送邮件demo (QQ邮箱)

    nodemailer是nodejs中的邮件发送模块,本文使用的版本为2.5.0 --下载模块 npm install nodemailer npm下载模块后,在项目中引入就可以使用: var node ...

  4. 第五篇:selenium调用IE问题(Protected Mode settings are not the same for all zones)

    代码信息: driver = webdriver.Ie()driver.get('http://www.baidu.com') 问题描述: raise exception_class(message, ...

  5. keil swd设置下载stm32f103c8t6.

    1.debug选项,选择jlink,2.utilities选择jlink3.加载flash算法.4.选择swd模式,其他基本上默认,这样就可以下载了对rom和ram设置需要说明一下:1,IROM1,前 ...

  6. DFS:POJ1088-滑雪(记忆化搜索)

    题目: 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 97666 Accepted: 37055 Description ...

  7. Xadmin添加用户小组件出错render() got an unexpected keyword argument 'renderer

    环境: Python 3.5.6 Django 2.1 Xadmin 原因: render函数在django2.1上有变化 解决方案: 1.在Python终端输入命令help('xadmin') 查看 ...

  8. Linux系统属性文件详解

    1)inode概述 中文意思就是索引节点(index node)第一部分是inode 第二部分是block inode主要用来存放文件属性信息的(也就是ls - l 的结果)包含的属性信息包括文件的大 ...

  9. 菜鸟学Linux - Linux文件属性

    在Linux中,文件的属性是一个很重要的概念,用户或者用户组对一个文件所拥有的权限,都可以从文件的属性得知. 我们可以通过ls -al命令,列出某个文件夹下面的所有文件(包括以.开头的隐藏文件).下面 ...

  10. mysql练习题练习

    1.数据库是按照原文制作的,表格结构一样具体存储的数据有些差异 原文地址:MySQL练习题 原答案地址:MySQL练习题参考答案 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: selec ...