传送门:
http://acm.hdu.edu.cn/showproblem.php?pid=1275
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1769 Accepted Submission(s): 548
#include<bits/stdc++.h> using namespace std; #define max_v 2050 double ans[max_v]; int main() { double va,vb,l,d; int num,t,i,j; scanf("%d",&t); while(t--) { scanf("%lf %lf %lf %d",&l,&va,&vb,&num); for(i=1,j=1;j<=1000;j++) { ans[i++]=(2.0*j-1.0)*l/(va+vb);//相遇 if(va!=vb)//避免除0 { ans[i++]=(2.0*j-1.0)*l/(fabs(va-vb));//追及 } } sort(ans,ans+i); d=ans[num]*va; while(d>l)//因为是往复运动 { d-=l; } d=min(d,l-d); printf("Time=%0.3lf Dist=%0.3lf\n",ans[num],d); } return 0; }
原文:https://www.cnblogs.com/yinbiao/p/9326293.html