Pinball(物理题)

                                              Pinball

             Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
                              Total Submission(s): 0    Accepted Submission(s): 0


 

Problem Description

There is a slope on the 2D plane. The lowest point of the slope is at the origin. There is a small ball falling down above the slope. Your task is to find how many times the ball has been bounced on the slope.

It's guarantee that the ball will not reach the slope or ground or Y-axis with a distance of less than 1 from the origin. And the ball is elastic collision without energy loss. Gravity acceleration g=9.8m/s2.

 

Input

There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 100), indicating the number of test cases.

The first line of each test case contains four integers a, b, x, y (1 ≤ a, b, -x, y ≤ 100), indicate that the slope will pass through the point(-a, b), the initial position of the ball is (x, y).

 

Output

Output the answer.

It's guarantee that the answer will not exceed 50.

 

Sample Input

 

1 5 1 -5 3

 

Sample Output

2

题意:有一个小球,从静止在重力作用下,落在一个斜面上,每次接触后就反弹,问在斜面上弹几次。

看到物理题格外亲切,尤其是这种不用自己算,g还等于9.8的题,格外令人开心。

将速度与加速分成斜面法向和斜面切向,每两次弹起之间的时间相同,嗯,没错,图大概长这样。

#include<bits/stdc++.h>
#define show(a) cout<<#a<<'='<<a<<endl;
#define ind(a) scanf("%lf",&a)
#define in(a) scanf("%d",&a)
using namespace std;

int main()
{
   int T;
   double a,b,x,y;
   const double pi=acos(-1.);
   const double g=9.8;
   int ans;
   in(T);
   while(T--)
   {
       ind(a);ind(b);ind(x);ind(y);
       ans=1;
       double tan=b/a;//show(tan);
       double sin=b/sqrt(b*b+a*a);//show(sin);
       double y0=-x/a*b;
       double h=y+x/a*b;//show(h);
       double t=sqrt(2*h/g);//show(t);
       double vy=g*t*sin;//show(vy);
       double s=sqrt(y0*y0+x*x);//show(s);
       while(s>0)
       {
           s-=vy*2*t+g*sin*2*t*t;//show(s);
           vy+=g*sin*2*t;//show(vy);
           ans++;
       }
       ans--;
       printf("%d\n",ans);
   }
   return 0;
}

猜你喜欢

转载自blog.csdn.net/sadsummerholiday/article/details/81515474