1166: Billiards collision Time Limit:1 Sec Memory limit:128 MB
Submit:21 Solved:5
[Submit] [Status] [Web Board] [Edit] Description
In a planar Cartesian coordinate system, the billiard table is a rectangle in the lower left corner (0,0), upper right corner (L,W). There is a spherical sphere (x,y), and a round ball with a radius of R is placed on the billiard table (the whole ball is in the billiard table). After the impact, the ball along the polar angle of a ray (i.e.:x Positive half axis counterclockwise to this ray angle is a) fly out, each encounter the table with a full elastic collision (the rate of the ball is constant, the reflection angle is equal to the angle of incidence).
If the velocity of the ball is v, where is the sphere after thes time unit?
Input
The input file contains up to 25 sets of test data, one row per data, 8 positive integers L,W,x,y,R,a,v, s(100<=L,W<=105, 1<=R<=5,r<=x<= L-R,R<=y<=W-R, 0<=a< 1<=v,s<=105), meaning see title description. L=W=x=y=R=a=v=s= 0 means that the input ends and your program should not handle this line.
Output
For each set of data, the output is only one row, containing two real numbers x, y, indicating that the globe coordinates are (x,y). x and y should be rounded to preserve two decimal places.
Sample INPUT100 5 2 5 1 9999 0 0 0 0 0 0 0 0 Sample Output80.00 56.00 71.00 10.00 hintso Urce
The sixth session of Hunan Province College students computer Program design Contest
according to the mentality of peach sister will be the movement of orthogonal decomposition, a back and forth for the cycle, the cycle of the remainder, and then the negative direction of movement into the positive direction of movement, the next is the cross-boundary judgment.
#include <stdio.h> #include <string.h> #include <math.h> const Double PI = ACOs (-1.0); int L, W, X, Y, R, A, V, S; Double XV, YV, XC, YC; int main () {//Freopen ("Stdin.txt", "R", stdin); while (scanf ("%d%d%d%d%d%d%d%d", &l, &w, &x, &y, &r, &a, &v, &s), x) {L-= R * 2; W-= R * 2; X-= R; Y-= R; XV = v * cos (A * pi/180.0); YV = v * sin (A * pi/180.0); XC = Fmod (Fmod (XV * s, L * 2.0) + L * 2.0, L * 2.0); YC = Fmod (Fmod (YV * s, W * 2.0) + W * 2.0, W * 2.0); XC + = x; YC + = y; if (XC >= 2 * l) XC-= 2 * l; else if (XC > L) XC = L-(xc-l); if (YC >= 2 * w) YC-= 2 * w; else if (YC > W) YC = W-(yc-w); printf ("%.2lf%.2lf\n", XC + R, YC + R); } return 0; }/************************************************************** problem:1166 User:changmu language:c++ result:accepted Time:4 ms memory:828 KB ****************************************************************/
HPU1166 Billiard clash