UVA - 10387 Billiard

来源:互联网 发布:nginx 内置全局变量 编辑:程序博客网 时间:2024/05/19 18:44

题目大意:球在桌中心与水平线成一个角度发射,最后返回出发点,给出时间、碰撞水平边和垂直边的次数,求发射角度和速度。

解题思路:根据反射的对称性,水平方向总路程为 a*m,竖直方向 b*n,速度根据勾股定理求得总路程除以时间得到,弧度 atan(b*n/a*m) 再 * 180 / PI 化为角度。

#include<iostream> #include<cstdio>#include<string.h>#include<stdlib.h>#include<cmath>using namespace std;const double PI = acos(-1.0);int main() {    double a, b, s, m, n;    while(scanf("%lf%lf%lf%lf%lf", &a, &b, &s, &m, &n) != EOF) {    if (!(a || b || s || m || n)) break;    double x = a * m;    double y = b * n;    double ang = atan( y / x ) * 180 / PI;    double v = sqrt(x * x + y * y) / s;    printf("%.2lf %.2lf\n", ang, v);     }    return 0; }
1 0