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.
这里写图片描述

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<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
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;
} 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值