2018HDU多校联赛第六场 6373 Pinball

题意

给定一个斜面,从某处让一个小球作自由落体运动,求小球与斜面的碰撞次数(假设都为弹性碰撞)。

分析

题图如下,x轴、y轴是虚拟的。

根据高中物理的套路,沿斜面方向分解重力加速度即可。

#include<bits/stdc++.h>
using namespace std;

const double g = 9.8;
const double EXP = 0.000001;
double a, b, x, y;

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%lf%lf%lf%lf", &a, &b, &x, &y);
        if(a * y + b * x < EXP)
        {
            printf("0\n");
            continue;
        }
        double sinn = b / sqrt(a*a + b*b), coss = a / sqrt(a*a + b*b);
        double all_t = sqrt(2 * ((x / coss) * (sinn  - 1 / sinn) + y ) / g);  //沿斜面的时间
        double t = sqrt(2 * (y + x * sinn / coss) / g);   //垂直斜面的单次时间
        //printf("%f  %f\n", all_t, t);
        int tmp = (int)((all_t + EXP) / t);
        printf("%d\n", (tmp + 1) / 2);
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/lfri/p/11329711.html