B - The Moving Points
来源:互联网 发布:mac怎么登陆两个微信 编辑:程序博客网 时间:2024/06/07 15:56
There are
The first line has a number
For each test case, first line has a single number
For next
That is to say, after
For test case Case #X:
first, then output two numbers, rounded to
2
2
0 0 1 0
2 0 -1 0
2
0 0 1 0
2 1 -1 0
Case #1: 1.00 0.00
Case #2: 1.00 1.00
/*【题意】:
02
给N个点,给出N个点的方向和移动速度,求每个时刻N个点中任意两点的最大值中的最小值,以及取最小值的时刻
03
解析:
04
两个点为例,任意两个点,按照自己的方向移动,一般情况下是,先两点慢慢接近,直到最近距离,然后慢慢远离,后面越来越远,图像画出来有点像抛物线,
05
这题就是抛物线求最小值,三分:先二分时间,按照斜率确定移动方向,直到移动到抛物线的最低端
06
注意题目精度,每次最好分1e-5以上,才能保证正确性
07
*/
#include <iostream>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
const int N=330;
const double eps=1e-6;
double x[N];
double y[N];
double vx[N];
double vy[N];
int n;
double calt(double t)//最长路径
{
double sum=0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
{
double x1=x[i]+vx[i]*t;
double y1=y[i]+vy[i]*t;
double x2=x[j]+vx[j]*t;
double y2=y[j]+vy[j]*t;
sum=max(sum,sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
return sum;
}
double sanfen()//最短时间//求凹凸线性的极值
{
double l=0,r=1e10;
while(r-l>=eps)
{
double mid=(l+r)/2;
double midmid=(mid+r)/2;//三分时间
double tmp1=calt(mid);
double tmp2=calt(midmid);
if(tmp2>tmp1)//舍弃右区间
r=midmid-eps;
else//舍弃左区间
l=mid+eps;
}
return l;
}
int main()
{
int t;
cin>>t;
for(int k=1;k<=t;k++)
{
cin>>n;
for(int i=0;i<n;i++)
cin>>x[i]>>y[i]>>vx[i]>>vy[i];
double h=sanfen();
printf("Case #%d: %.2lf %.2lf\n",k,h,calt(h));
}
}
- B - The Moving Points
- hdu_4717 The Moving Points
- hdu4717 The Moving Points
- HDU4717-The Moving Points
- hdu4717-(The Moving Points)
- The Moving Points HDU
- 【hdu4717】The Moving Points
- HDU 4717 The Moving Points
- HDU 4717 The Moving Points
- hdu 4717 The Moving Points
- HDU 4717 The Moving Points
- hdu 4717 The Moving Points
- HDU4717 :The Moving Points(三分法)
- hdu 4717- The Moving Points
- HDU 4717 The Moving Points
- hdu4717 The Moving Points 三分
- HDOJ 4717 The Moving Points
- HDU 4717 The Moving Points
- 墨香带你学Launcher之(二)-数据加载流
- 小程序学习之toast和input
- oracle数据库用户加锁、解锁以及修改密码等操作
- js事件冒泡与捕获
- MATLAB的简单动画制作
- B - The Moving Points
- linux ftp安装记录
- 详讲H5、WebApp项目中常见的坑以及注意事项
- UVa-101(STL)
- 草坪上大战正酣躺床上玩
- 九度 oj 题目1446:Head of a Gang
- Android for循环请求如何得到顺序的结果
- 开始写博客
- Android项目中嵌入RN常见问题汇总