Fork me on GitHub

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……

posted @   Gifur  阅读(346)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
TOP
点击右上角即可分享
微信分享提示