hdu 4717 The Moving Points(三分)

题目链接:hdu 4717 The Moving Points

题意:

在二维平面上有n个点,每个点给出移动的方向和速度。

问在某个时刻,这些点中最大距离最小是多少,输出时刻和距离。

题解:

我们可以知道,每个点对的距离要么是单调递增,要么是有一个峰的函数。

举例画一下可知道合成的这个函数最多只有一个峰,所以可以用三分求解。

 1 #include<bits/stdc++.h>
 2 #define F(i,a,b) for(int i=a;i<=b;++i)
 3 using namespace std;
 4
 5 const int N=307;
 6 int t,n,cas;
 7 double X[N],Y[N],VX[N],VY[N];
 8
 9 double dis(double a,double b,double c,double d){return sqrt((c-a)*(c-a)+(d-b)*(d-b));}
10
11 double check(double time)
12 {
13     double mx=0;
14     F(i,1,n)F(j,1,n)
15     mx=max(mx,dis(X[i]+time*VX[i],Y[i]+time*VY[i],X[j]+time*VX[j],Y[j]+time*VY[j]));
16     return mx;
17 }
18
19 int main(){
20     scanf("%d",&t);
21     while(t--)
22     {
23         scanf("%d",&n);
24         F(i,1,n)scanf("%lf%lf%lf%lf",X+i,Y+i,VX+i,VY+i);
25         double l=0,r=1e7,mid,mmid;
26         F(i,1,100)
27         {
28             mid=(l+r)/2,mmid=(mid+r)/2;
29             if(check(mid)<check(mmid))r=mmid;else l=mid;
30         }
31         printf("Case #%d: ",++cas);
32         check(l)>check(r)?printf("%.2f %.2f\n",l,check(l)):printf("%.2f %.2f\n",r,check(r));
33     }
34     return 0;
35 }

时间: 2024-08-04 15:48:23

hdu 4717 The Moving Points(三分)的相关文章

hdu 4717 The Moving Points(三分)

http://acm.hdu.edu.cn/showproblem.php?pid=4717 大致题意:给出每个点的坐标以及每个点移动的速度和方向.问在那一时刻点集中最远的距离在所有时刻的最远距离中最小. 比赛时一直以为是计算几何,和线段相交什么的有关.赛后队友说这是道三分,仔细想了想确实是三分,试着画画图发现它是一个凸性函数,存在一个最短距离.然后三分时间就可以了. #include <stdio.h> #include <iostream> #include <map&g

HDU 4717 The Moving Points (三分法)

题意:给n个点的坐标的移动方向及速度,问在之后的时间的所有点的最大距离的最小值是多少. 思路:三分.两点距离是下凹函数,它们的max也是下凹函数.可以三分. #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<cstdlib> #include<string> #include<cmath> #include&

hdu4717The Moving Points(三分)

链接 需要特判一下n=1的时候 精度调太低会超时 1 #include <iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<stdlib.h> 6 #include<vector> 7 #include<cmath> 8 #include<queue> 9 #include<set> 1

HDU-4717 The Moving Points(凸函数求极值)

The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2122    Accepted Submission(s): 884 Problem Description There are N points in total. Every point moves in certain direction and

HDU 3400 Line belt (三分再三分)

HDU 3400 Line belt (三分再三分) ACM 题目地址: HDU 3400 Line belt 题意: 就是给你两条线段AB , CD ,一个人在AB以速度p跑,在CD上以q跑,在其他地方跑速度是r.问你从A到D最少的时间. 分析: 先三分AB上的点,再三分CD上的点即可. 证明: 设E在AB上,F在CD上. 令人在线段AB上花的时间为:f = AE / p,人走完Z和Y所花的时间为:g = EF / r + FD / q. f函数是一个单调递增的函数,而g很明显是一个先递减后递

hdu 4717(三分) The Moving Points

链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 n个点,给出初始坐标和移动的速度和移动的方向,求在哪一时刻任意两点之间的距离的最大值的最小. 对于最大值的最小问题首先就会想到二分,然而由于两点之间的距离是呈抛物线状,所以三分的方法又浮上脑海,当然二分也可以做,不过思维上更复杂一些 1 #include<cmath> 2 #include<cstdio> 3 #include<cstring> 4 #include<

hdu 4717 三分查找

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 题      意:n个点的起始坐标和它们的运动方向,求这n个点的在哪个时刻最远距离最小 题      解:两点的距离为一个二次函数,对时间进行三分查找答案 #include <iostream> #include <cstdio> #include <cmath> using namespace std; struct point { double x,y; doub

hdu 4454 Stealing a Cake(三分)

题目链接:hdu 4454 Stealing a Cake 题目大意:给定一个起始点s,一个圆形,一个矩形.现在从起点开始,移动到圆形再移动到矩形,求最短距离. 解题思路:在圆周上三分即可.即对角度[0,2*pi]三分,计算点和矩形的距离可以选点和矩形四条边的距离最短值. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std

hdu 5626 Clarke and points

Clarke and points Problem Description The Manhattan Distance between point A(XA,YA) and B(XB,YB) is |XA - XB| + |Xb - YB|; the coordinate of each point is generated by the followed code. Input long long seed;inline long long rand(long long l, long lo