hdu6373 Pinball

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.
hdu6373 Pinball_第1张图片

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

可以把斜面看成水平面,把重力加速度化为垂直平面向下的加速度和平行斜面向下的加速度,这样小球在平行与斜面的方向一直在做匀加速运动,可以计算出小球离开斜面所化时间t,小球在垂直斜面上则是上下弹跳,计算出小球弹跳一次的时间,就可以算出小球在t时间内弹跳了几次。

#include
#include
#include
#include
#include
using namespace std;
const double pi=acos(-1.0);
const double g=9.8;

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        double a,b,x,y;
        scanf("%lf%lf%lf%lf",&a,&b,&x,&y);
        double th=atan(b/a);
        //printf("%f\n",th);
        double dg=g*cos(th);
        double fg=g*sin(th);
        double h=cos(th)*(y+b/a*x);
        //printf("%f\n",h);
        double l=-x/cos(th)+(y+b/a*x)*sin(th);
        //printf("%f\n",l);
        double tim=sqrt(2*l/g/sin(th));
        double ti=sqrt(2*h/g/cos(th));
        //printf("%f %f\n",tim,ti);
        int ans=(int)((tim-ti)/(2*ti));
        ans++;
        printf("%d\n",ans);
    }
    return 0;
} 

你可能感兴趣的:(hdu6373 Pinball)