HDU 6373 Pinball (2018 Multi-University Training Contest 6)

Pinball

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


 

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

题目大意:

给出a,b,x,y的值给你,让你求出小球在斜面上弹了几次。

解法:

简单的高中物理题。因为已经给出了a,b。(注意给的是a,题目中的点是-a)我们可以求出这个斜面的斜率k。根据k=y1(未知)/x(题目输入的),我们可以求出在斜面上的y1坐标,让y-y1就可以得到球与斜面竖直方向上的距离h。利用高中物理的简单公式:h=1/2gt^2可以得到时间t。这个时候我们可以对重力加速度进行分解。小球在平行斜面的方向做匀加速直线运动。利用下斜率就能求出总距离dist,求出运动的时间t1,t1减去distance所需要的时间(也就是t)。再除以2倍的t(因为小球弹上去,再下来,要2倍的时间),最后再加上最开始的一次,就是答案了。

#include <bits/stdc++.h>
#define g 9.8
using namespace std;
int main(){
	int t;
	double a, b, x, y;
	scanf("%d",&t);
	while( t-- ){
		scanf("%lf%lf%lf%lf", &a, &b, &x, &y);
		a =- a;//题目中的是-a,转换一下 
		double tep = sqrt( a * a + b * b );
		double g1 = g * ( b ) / tep;//平行斜面的加速度 
		double bts = y - x * b / a;//小球距离斜面竖直方向上的距离 
		double t = sqrt ( 2 * bts / g );//小球下降到斜面所需要的时间 
		double bts1 = ( bts * b / tep );//distance 
		double s = sqrt( x * x + ( x * b / a ) * ( x * b / a ) );//dis 
		s += bts1;
		double t1 = sqrt( 2 * s / g1 );//所需要的总时间 
		t1 -= t;//减去dis的时间 
		int ans = t1 / ( 2 * t );//除以2倍的时间,因为上升和下降都需要时间 
		printf("%d\n",ans + 1);//最开始的一次要加上去 
	}
}
发布了22 篇原创文章 · 获赞 19 · 访问量 3544

猜你喜欢

转载自blog.csdn.net/KnightHONG/article/details/81535609