用动能定理 ,与在peek(山顶)时的动能和bitter(坏土豆)的所在位置的动能比较,找出最大值,求出速度即可。 因为忽略了摩擦力
#include<stdio.h> #include<string.h> #include<math.h> #define g 20 struct spot{ double x,y; }p[1005]; int main() { int t,cas=1; scanf("%d",&t); while(t--) { int numpeek,numbitter,sweetw,i; scanf("%d%d%d",&numpeek,&numbitter,&sweetw); double maxv=0; for( i=0;i<numpeek;i++) { scanf("%lf%lf",&p[i].x,&p[i].y); if(p[i].y>p[0].y) { double tempv=sqrt(2*g*(p[i].y-p[0].y)); if(tempv>maxv) maxv=tempv; } } int j; double d,v,m; double tempx,h,temp; for(i=0;i<numbitter;i++) { scanf("%lf%lf%lf",&d,&v,&m); d+=p[0].x; for(j=0;j<numpeek-1;j++) { if(d>=p[j].x&&d<=p[j+1].x) { if(p[j].y<=p[j+1].y) { tempx=d-p[j].x; h=tempx*(p[j+1].y-p[j].y)/(p[j+1].x-p[j].x)+(p[j].y); temp=sqrt((v*v+2*g*h-2*g*p[0].y)); if(temp>maxv) maxv=temp; } else { tempx=p[j+1].x-d; h=tempx*(p[j].y-p[j+1].y)/(p[j+1].x-p[j].x)+(p[j+1].y); temp=sqrt((v*v+2*g*h-2*g*p[0].y)); if(temp>maxv) maxv=temp; } } } } printf("Case %d: ",cas++); printf("%.2lf\n",maxv); } return 0; }