zoukankan      html  css  js  c++  java
  • Uva 10387 Billiard

    Problem A: Billiard

    In a billiard table with horizontal side a inches and vertical side b inches, a ball is launched from the middle of the table. After s > 0 seconds the ball returns to the point from which it was launched, after having made m bounces off the vertical sides and n bounces off the horizontal sides of the table. Find the launching angle A (measured from the horizontal), which will be between 0 and 90 degrees inclusive, and the initial velocity of the ball.

    Assume that the collisions with a side are elastic (no energy loss), and thus the velocity component of the ball parallel to each side remains unchanged. Also, assume the ball has a radius of zero. Remember that, unlike pool tables, billiard tables have no pockets.

    Input

    Input consists of a sequence of lines, each containing five nonnegative integers separated by whitespace. The five numbers are: absm, and n, respectively. All numbers are positive integers not greater than 10000.

    Input is terminated by a line containing five zeroes.

    Output

    For each input line except the last, output a line containing two real numbers (accurate to two decimal places) separated by a single space. The first number is the measure of the angle A in degrees and the second is the velocity of the ball measured in inches per second, according to the description above.

    Sample Input

    100 100 1 1 1
    200 100 5 3 4
    201 132 48 1900 156
    0 0 0 0 0
    

    Sample Output

    45.00 141.42
    33.69 144.22
    3.09 7967.81


    #include<stdio.h>
    #include<math.h>
    int main()
    {
        int a, b, m, n, s;
        double angle, v;
        double pi = acos(0.0)*2;
        while(scanf("%d%d%d%d%d", &a, &b, &s, &m, &n) != EOF)
        {
            if(a+b+s+m+n == 0) break;
            angle = atan(1.0*b*n/(1.0*a*m))/pi*180;
            while(angle > 90) angle -= 90;
            v = sqrt(1.0*a*a*m*m+1.0*b*b*n*n)/s;
            printf("%.2lf %.2lf\n", angle, v);
            
        }
        return 0;
    }

    解题思路:

    起点在中间,速度没有改变,最终回到原点。那么可以得出的结论是:在水平边上撞击了多少次就代表着垂直的路程它走了多少次;在垂直边上撞击多少次就代表着水平的路程它走了多少次,根据勾股定理可以得出它走的路程总长度,再加上有时间,很快就能算出速度。至于角度,根据刚才得到的三角形,求角的运算就简单了,因为整个过程一直都没有受到其他的外力,所以不像重力作用的抛物线,什么速度形成的角的tan值是路程形成的角的tan的1/2……

  • 相关阅读:
    axios
    es6
    $route监听路由变化
    容易挂
    自定义全局组件/插件
    eslintrc.js
    dev-server.js
    webpack-dev-server.js
    怎么消除间隔间的空白字符
    es6语法
  • 原文地址:https://www.cnblogs.com/liaoguifa/p/2954976.html
Copyright © 2011-2022 走看看