标签:des style blog http color java os io
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 902 Accepted Submission(s):
259
一种是相遇:满足关系是 (va+vb)*t=L*(2*n-1)
一种是追及: 满足关系是 |va-vb|*t=L*(2*n-1)
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> using namespace std; double t[2050];//不能定义time[].....CE 了。。。 int n,num,m,ia,ib,i,j; double len,va,vb,dis; int main() { scanf("%d",&n); while(n--) { cin>>len>>va>>vb>>num; j=1; for(i=1; i<=1000; i++) { t[j++]=(2*i-1)*len/(va+vb);//一种是相遇:满足关系是 (va+vb)*t=L*(2*n-1) t[j++]=(2*i-1)*len/fabs(va-vb);//一种是追及: 满足关系是 |va-vb|*t=L*(2*n-1) } sort(t,t+j); dis=t[num]*va; while(dis-len>0) dis-=len; if(len-dis<dis) dis=len-dis; printf("Time=%.3lf Dist=%.3lf\n",t[num],dis); } return 0; }
先前忘了 追及了,,,,
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; double dis,va,vb; int T,t; double time,dist,la,lb; int main() { scanf("%d",&T); while(T--) { scanf("%lf%lf%lf%d",&dis,&va,&vb,&t); time=(dis*(t-1)*2+dis)/(va+vb); la=time*va-((int)((time*va)/dis))*dis; lb=dis-la; // lb=time*vb-((int)((time*vb)/dis))*dis; printf("Time=%0.3lf Dist=%0.3lf\n",time,la>lb?lb:la); } return 0; }
两车追及或相遇问题(hdu1275)数学题,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/yuyixingkong/p/3917794.html