当前位置 : 主页 > 编程语言 > python >

hdu 4717 The Moving Points(三分,4级)

来源:互联网 收集:自由互联 发布时间:2023-03-22
The Moving Points Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 103Accepted Submission(s): 35 Problem Description There are N points in total. Every point moves in certain direction and

The Moving Points

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

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 X i, Y i, VX i and VY i (-10 6 <= X i, Y i <= 10 6, -10 2 <= VX i , VY i <= 10 2), (X i, Y i) is the position of the i th point, and (VX i , VY i) is its speed with direction. That is to say, after 1 second, this point will move to (X i + VX i , Y i + VY i).

 

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

思路:三分

#include<iostream>#include<cstring>#include<cstdio>#include<cmath>#define FOR(i,a,b) for(int i=a;i<=b;++i)using namespace std;const int mm=1e5+9;const double mx=1e-6;int n;class Dot{public: double x,y,vx,vy;}f[mm];double tim,dis;double getdis(double x,double y,double xx,double yy){ return sqrt( (x-xx)*(x-xx)+(y-yy)*(y-yy) );}double get(double mid){ double d=0; FOR(i,1,n)FOR(j,i+1,n) { d=max(d,getdis(f[i].x+f[i].vx*mid,f[i].y+f[i].vy*mid,f[j].x+f[j].vx*mid,f[j].y+f[j].vy*mid)); } return d;}void getans(){ double l=0,r=1e9,mid; double ll,rr; while(r-l>mx) { ll=(l+l+r)/3; rr=(l+r+r)/3; if(get(ll)>get(rr)) { l=ll; } else { r=rr; } } tim=(l+r)/2+mx;dis=get(tim); printf("%.2lf %.2lf\n",tim,dis); //cout<<tim<<" "<<dis<<endl;}int main(){ int cas; while(~scanf("%d",&cas)) { FOR(ca,1,cas) { printf("Case #%d: ",ca); scanf("%d",&n); FOR(i,1,n) { scanf("%lf%lf%lf%lf",&f[i].x,&f[i].y,&f[i].vx,&f[i].vy); } getans(); } } return 0;}

上一篇:Codeforce 342E - Xenia and Tree(LCA+spfa,5级)
下一篇:没有了
网友评论