hdu 4717

来源:互联网 发布:安卓手机plc编程软件 编辑:程序博客网 时间:2024/06/14 20:33

传送门

题意:在一个平面上有很多运动的点,问那一个时刻,所有点的最大距离最小。 
思路:分析对于两个点,他们之间的距离随时间一定是一个二次函数,距离一定是先减小,再增大。所以用三分逼近这个最小值。

The Moving Points

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2036    Accepted Submission(s): 841


Problem Description
There are N points in total. Every point moves in certain direction and certain speed. We want to know at what time that the largest distance between any two points would be minimum. And also, we require you to calculate that minimum distance. We guarantee that no two points will move in exactly same speed and direction.
 

Input
The rst line has a number T (T <= 10) , indicating the number of test cases.
For each test case, first line has a single number N (N <= 300), which is the number of points.
For next N lines, each come with four integers Xi, Yi, VXi and VYi (-106 <= Xi, Yi <= 106, -102 <= VXi , VYi <= 102), (Xi, Yi) is the position of the ith point, and (VXi , VYi) is its speed with direction. That is to say, after 1 second, this point will move to (Xi + VXi , Yi + VYi).
 

Output
For test case X, output "Case #X: " first, then output two numbers, rounded to 0.01, as the answer of time and distance.
 

Sample Input
220 0 1 02 0 -1 020 0 1 02 1 -1 0
 

Sample Output
Case #1: 1.00 0.00Case #2: 1.00 1.00
 

Source
2013 ACM/ICPC Asia Regional Online —— Warmup2
 

Recommend
zhuyuanchen520

//china no.1#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>using namespace std;#define pi acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x) memset(x,0,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);typedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;//const int dx[]={-1,0,1,0,-1,-1,1,1};//const int dy[]={0,1,0,-1,1,-1,1,-1};const int maxn=1e3+5;const int maxx=1e5+100;const double EPS=1e-7;const int MOD=10000007;#define mod(x) ((x)%MOD);template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)int n;struct node{    double x,y,vx,vy;}Q[maxx];double cross(node a,node b,double t){    return (a.x+a.vx*t-b.x-b.vx*t)*(a.x+a.vx*t-b.x-b.vx*t)+(a.y+a.vy*t-b.y-b.vy*t)*(a.y+a.vy*t-b.y-b.vy*t);}double calc(double x){    double ans=0;    FOR(1,n,i)        FOR(i+1,n,j)            ans=max(ans,cross(Q[i],Q[j],x));    //cout<<ans<<endl;    return ans;}int main(){    int t;    cin>>t;    FOR(1,t,cas)    {        cin>>n;        FOR(1,n,i)            cin>>Q[i].x>>Q[i].y>>Q[i].vx>>Q[i].vy;        double l=0,r=1e8;        int len=300;        W(len--)        {            double mid=l+(r-l)/3;            double midmid=r-(r-l)/3;            if(calc(mid)<calc(midmid)) r=midmid;            else l=mid;        }       // printf("%.2lf\n",sqrt(calc(l)));        printf("Case #%d: %.2lf %.2lf\n",cas,l,sqrt(calc(l)));    }}



原创粉丝点击