UVa 10387 Billiard: Computational Geometry & Reflection

Source: Internet
Author: User
Tags in degrees reflection time limit

10387-billiard

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=101&page=show_ problem&problem=1328

In a billiard table with horizontal side a inches and vertical side B inches, a ball are launched from the middle of the TA ble. After s > 0 seconds the "ball returns" to "point" from which it is launched, after have made m bounces off the Verti Cal sides and N bounces off the horizontal sides of the table. Find the launching angle A (measured from the horizontal), which would be between 0 and degrees inclusive, and the Initi Al velocity of the ball.

Assume that's 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 by separated. The five numbers are:a, B, S, M, and N, respectively. All numbers are positive integers not greater than 10000.

The 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. The measure of the angle A in degrees and the second are the velocity of the ball measured in inches pe R second, according to the description above.

Sample Input

1 1 1 MB
5 3 4
201 132 1900 156
0 0 0 0 0

Sample Output

45.00 141.42
33.69 144.22
3.09 7967.81

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Idea: The trajectory of a small ball can be transformed into a straight line. How to transform?

As shown in the figure above, imagine the ball moving on an infinitely expanding pool surface, which is to "splice" the motion trajectory of the ball.

So we get a straight line and the back is fine.

Complete code:

/*0.018s*/
    
#include <cstdio>  
#include <cmath>  
const Double One_radian = 90.0/acos (0);/// 1 radians corresponds to the angle value  
    
int main ()  
{  
    int A, B, S, m, N;  
    while (scanf ("%d%d%d%d%d", &a, &b, &s, &m, &n), a)  
        printf ("%.2f%.2f\n", One_radian * ATAN (DOUBL e) b * N/A/M), Hypot (b * N, A * m)/s);  
    return 0;  
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.