2018 Multi-University Training Contest 6 Pinball

Pinball

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


 

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

题意:有一个小球在x,y处朝斜面落下,然后给你斜面的一点(a,b),问小球会与斜面碰撞几次;

题解:将斜面看成一个坐标系,则小球在水平和竖直方向都做加速运动,之后模拟小球的运动即可;

下面附上我的代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#define LL long long
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define lson o<<1
#define rson o<<1|1
using namespace std;
double g = 9.8;
double Cal(double x, double y)
{
	return sqrt(x * x + y * y);
}
int main()
{
	int T;
	double X, Y, x, y, a, b;
	cin >> T;
	while(T--)
	{
		scanf("%lf %lf %lf %lf", &a, &b, &x, &y);
		double tans = fabs(b) / fabs(a);
		double sins = fabs(b) / Cal(a, b);
		double coss = fabs(a) / Cal(a, b);
		double Y = fabs(x) * tans;
		double X = x;
		double v0 = sqrt(2.0 * g * (y - Y));
		double t = 2.0 * v0 / g;
		double dist = Cal(X, Y);
		double vx = v0 * sins;
		double gx = g * sins;
		int ans = 0;
		while(dist >= 1)
		{
			dist -=  (vx * t + 0.5 * gx * t * t);
			vx += gx * t;
			ans++;
		} 
		printf("%d\n", ans);
	}
    return 0;
}

猜你喜欢

转载自blog.csdn.net/gtuif/article/details/81509918