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
Source
2018 Multi-University Training Contest 6
题意就是问你小球在斜面上能弹几次,物理推导问题
根据物理上学的类平抛运动可以推出每次弹出的相对斜面的位移之比为1:2:3:4.......,所以只需要算出第一次的位移就行,由于没有能量损失,所以由动能定理可得第一次位移s=8Hsinθ,之后以此类推就行
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
int t, sum;
double a, b, x, y, S, j, c, H, L;
scanf("%d", &t);
while (t--)
{
int s = 0;
sum = 0;
scanf("%lf %lf %lf %lf", &a, &b, &x, &y);
j = sin(atan(b / a));
c = fabs(b / a * x);
H = y - c;
L = sqrt(c*c + x * x);
//printf("%lf %lf %lf %lf %lf\n",j,c,H,L,s);
for (int i = 1; i <= 50; i++)
{
sum++;
s += i;
if ((double)s*8.0*H*j > L)
{
printf("%d\n", sum);
break;
}
}
}
return 0;
}