GYM 100971 F.Two Points(三分)
来源:互联网 发布:淘宝晚班客服兼职 编辑:程序博客网 时间:2024/05/05 05:31
Description
给出两个点的初始二维坐标和速度向量,问这两个点运动过程中的最短距离
Input
第一行四整数ax,ay,bx,by表示两个点的初始二维坐标,第二行四个整数vax,vay,vbx,vby表示两个点的速度向量
(-1e4<=ax,ay,bx,by,vax,vay,vbx,vby<=1e4))
Output
输出两个点运动过程中的最短距离
Sample Input
1 1 2 2
0 0 -1 0
Sample Output
1.000000000000000
Solution
三分时间即可
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 1111#define eps 1e-8struct node{ double x,y; node operator*(const double &n)const { node a; a.x=x*n,a.y=y*n; return a; } node operator+(const node &b)const { node a; a.x=x+b.x,a.y=y+b.y; return a; }}a,b,va,vb;int sign(double x){ if(fabs(x)<eps)return 0; if(x>eps)return 1; return -1;}double dis(node a,node b){ double x=b.x-a.x,y=b.y-a.y; return sqrt(x*x+y*y);}int main(){ while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&va.x,&va.y,&vb.x,&vb.y)) { double l=0,r=1e12,mid1,mid2,ans=dis(a,b); int T=100000; while(T--) { mid1=0.5*(l+r),mid2=0.5*(mid1+r); double d1=dis(a+va*mid1,b+vb*mid1),d2=dis(a+va*mid2,b+vb*mid2); ans=min(ans,d1),ans=min(ans,d2); if(sign(d1-d2)<=0)r=mid2; else l=mid1; } printf("%.10f\n",ans); } return 0;}
0 0
- GYM 100971 F.Two Points(三分)
- Gym 100971F Two Points
- GYM 100488 F.Two Envelopes(水~)
- hdu 4717 The Moving Points(三分)
- hdu 4717 The Moving Points(三分)
- HDU 4717 The Moving Points (三分)
- HDU4717 The Moving Points(三分)
- ICPCCamp2017 Day 4 F Factory(三分套三分)
- hdoj4717The Moving Points【三分】
- Codeforces 818F Level Generation(三分)
- [Gym-101350F] F
- Restore Points Gym
- Gym 100685F Flood(拓扑排序)
- Gym - 100512F Funny Game(杂题)
- Gym - 101142F Folding(折半)
- codeforces gym 101142 F(思维)
- GYM 100247 F. Battle Fury(二分)
- GYM 100090 F.Asperger Syndrome(set)
- spring mvc 的action跳转
- Retrofit
- 基于win10系统的MongoDB基本安装
- Java网络编程:socket tcp编程
- 未完成题目
- GYM 100971 F.Two Points(三分)
- 一、v4l2文档之——v4l2 framework
- struts1讲解
- MATLAB学习(四)Excel读写数据
- C++读书笔记
- java 中的集合(一) 概述
- IDEA——IDEA使用Tomcat服务器出现乱码问题
- 多臂强盗(multi-armed bandit)问题探究
- 基于C++的二叉树的建立,前序中序后序遍历