HDU-6373 Pinball

博客围绕小球在斜面上的弹跳问题展开,给出问题描述、输入输出要求及示例。通过沿斜面建系,将重力加速度分解,把小球运动分解为沿斜面和垂直斜面的匀加速运动,计算出相关时间,进而得出小球弹跳次数的计算方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

### 关于HDU - 6609 的题目解析 由于当前未提供具体关于 HDU - 6609 题目的详细描述,以下是基于一般算法竞赛题型可能涉及的内容进行推测和解答。 #### 可能的题目背景 假设该题目属于动态规划类问题(类似于多重背包问题),其核心在于优化资源分配或路径选择。此类问题通常会给出一组物品及其属性(如重量、价值等)以及约束条件(如容量限制)。目标是最优地选取某些物品使得满足特定的目标函数[^2]。 #### 动态转移方程设计 如果此题确实是一个变种的背包问题,则可以采用如下状态定义方法: 设 `dp[i][j]` 表示前 i 种物品,在某种条件下达到 j 值时的最大收益或者最小代价。对于每一种新加入考虑范围内的物体 k ,更新规则可能是这样的形式: ```python for i in range(n): for s in range(V, w[k]-1, -1): dp[s] = max(dp[s], dp[s-w[k]] + v[k]) ``` 这里需要注意边界情况处理以及初始化设置合理值来保证计算准确性。 另外还有一种可能性就是它涉及到组合数学方面知识或者是图论最短路等相关知识点。如果是后者的话那么就需要构建相应的邻接表表示图形结构并通过Dijkstra/Bellman-Ford/Floyd-Warshall等经典算法求解两点间距离等问题了[^4]。 最后按照输出格式要求打印结果字符串"Case #X: Y"[^3]。 #### 示例代码片段 下面展示了一个简单的伪代码框架用于解决上述提到类型的DP问题: ```python def solve(): t=int(input()) res=[] cas=1 while(t>0): n,k=list(map(int,input().split())) # Initialize your data structures here ans=find_min_unhappiness() # Implement function find_min_unhappiness() res.append(f'Case #{cas}: {round(ans)}') cas+=1 t-=1 print("\n".join(res)) solve() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值