HDU-6373 Pinball

Pinball

Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 262144/262144 K (Java/Others)

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.8 m / s 2 g=9.8m/s^2 g=9.8m/s2.

Alt

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

Tips

题意:
如图所示,一个小球(可看作质点)从 ( x , y ) (x,y) (x,y) 除由静止自由下落,下方有一以原点为顶点,过点 ( − a , b ) (-a,b) (a,b) 的斜面。问小球在落地(落到 x x x 轴上)之前共弹了几次。

题解:
如下图所示,沿斜面建系,将重力加速度分解到与斜面平行的方向和与斜面垂直的方向,分别记作 g p = g sin ⁡ θ , g v = g cos ⁡ θ g_p=g\sin\theta,g_v=g\cos\theta gp=gsinθ,gv=gcosθ ,其中 θ = arctan ⁡ b a \theta=\arctan\frac{b}{a} θ=arctanab 是斜面的倾角。则小球在斜面上的运动就可以分解为沿着斜面方向的匀加速运动和沿着与斜面垂直方向的匀加速运动。计算出沿斜面方向运动结束的时间 t p t_p tp 和沿着与斜面垂直方向的一次下落时间 t v t_v tv ,则弹跳的次数即为 1 + ⌊ t p − t v 2 t v ⌋ 1+\left\lfloor\frac{t_p-t_v}{2t_v}\right\rfloor 1+2tvtptv 由于第一次下落是一半的周期,而之后都是起-落的循环,因此要先用总时间减去第一次下落的时间算出接下来弹跳的次数,再加上第一次的。

Alt

至于如何计算两个时间,首先来说, t v t_v tv 很容易计算,先计算 h = ( y + x tan ⁡ θ ) cos ⁡ θ = y cos ⁡ θ + x sin ⁡ θ h=(y+x\tan\theta)\cos\theta=y\cos\theta+x\sin\theta h=(y+xtanθ)cosθ=ycosθ+xsinθ ,然后用 h = 1 2 g v t v 2 h=\frac{1}{2}g_vt_v^2 h=21gvtv2 即可得出 t v = 2 ( y cos ⁡ θ + x sin ⁡ θ ) g cos ⁡ θ t_v=\sqrt{\frac{2(y\cos\theta+x\sin\theta)}{g\cos\theta}} tv=gcosθ2(ycosθ+xsinθ)

t p t_p tp 则与之相仿,首先计算 s = − x + ( y + x tan ⁡ θ ) sin ⁡ θ = y sin ⁡ θ − x cos ⁡ θ s=-x+(y+x\tan\theta)\sin\theta=y\sin\theta-x\cos\theta s=x+(y+xtanθ)sinθ=ysinθxcosθ ,可得 t p = 2 ( y sin ⁡ θ − x cos ⁡ θ ) g sin ⁡ θ t_p=\sqrt{\frac{2(y\sin\theta-x\cos\theta)}{g\sin\theta}} tp=gsinθ2(ysinθxcosθ)

至此本题结束。

Reference Code

#include <cstdio>
#include <cmath>
const double g=9.8;
int T,a,b,x,y;
int solve(){
	double k=-1.0*b/a;
	double t=atan(-k);
	double gp=g*sin(t);
	double gv=g*cos(t);
	double tp=sqrt(2*(y*sin(t)-x*cos(t))/gp);
	double tv=sqrt(2*(y*cos(t)+x*sin(t))/gv);
	return 1+(int)((tp-tv)/(2*tv));
}
int main(){
	scanf("%d",&T);
	while (T--){
		scanf("%d%d%d%d",&a,&b,&x,&y);
		printf("%d\n",solve());
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值