Input: Standard Input Output: Standard Output
� There is a rectangle on the cartesian plane, with bottom-left corner at (0,0) and top-right corner at (L,W). There is a ball centered at (x, y), with radius=R, shown below
At time 0, the ball starts to move along a ray with polar angle a (the angle from positive x-axis to the ray, rotating counter-clockwise). When hitting the rectangle boundary, the reflex angle always equals to the incidence angle. The ball's velocity is always v (i.e. it never changes when hitting the rectangle). Where is the center of the ball at time s?
Input
There will be at most 25 test cases, each contains a line with 8 integers L,W,x,y,R,a,v,s (100L,W109, 1R5, RxL - R, RyW - R, 0a < 360, 1v, s109), as stated above. The input terminates with L= W = x = y = R = a = v = s = 0, which should not be processed.
Output
For each test case, output a line containing two floating-point numbers x, y, rounded to two decimal points, indicating that the center of ball will be at (x, y) at time s.
题目大意:一个半径为R的圆以一个角度α和恒定速度v在一个L*W的场地中乱撞,撞墙后反射的方向与镜面反射相同。
思路:首先,一个圆在[0,L]、[0,W]里乱撞,相当于一个这个圆的圆心在[R, L-R], [R, W-R]里乱撞。答案也是要圆心,那么只考虑圆心即可。之后,速度是恒定的,横向速度和纵向速度也是不变的,假设场地为无限大,那么我们一开始就可以算出最终坐标(理论上来说极限数据会爆double的精度,但是AC了,我就不管了……要是真WA了我们可以试试long double……)。然后x、y完全可以分开算,他们之间一点影响都木有。于是考虑x,若有一堵墙在L-R处,如果没有墙L我们可以到达xi(超过了L-R),那么有墙我们就会到达2*(L-R) - xi;如果有墙在R,我们可以到达xi(小于R),那么我们就会到达2 * R - xi。不断重复直到xi落在[R, L-R]之间(极限数据这样搞可能会TLE,但是AC了,所以也不管了……)。Y一样搞法,不重复说了。
PS:不要找我要证明我不会,我只能说我觉得这样搞是对的。
代码(19MS):
1 #include <cstdio> 2 #include <iostream> 3 #include <algorithm> 4 #include <cstring> 5 #include <cmath> 6 using namespace std; 7 typedef long long LL; 8 9 const double PI = acos(-1.0); 10 const double EPS = 1e-4; 11 12 LL L, W, x, y, R, a, v, s; 13 14 int main() { 15 //cout<<cos(PI/2)<<endl; 16 while(cin>>L>>W>>x>>y>>R>>a>>v>>s) { 17 if(L == 0 && W == 0 && x == 0 && y == 0 && R == 0 && a == 0 && v == 0 && s == 0) break; 18 double nx = x + v * cos(PI * a / 180) * s, ny = y + v * sin(PI * a / 180) * s; 19 L -= R; 20 W -= R; 21 while(R >= nx + EPS || nx - EPS >= L) { 22 if(R >= nx) nx = 2 * R - nx; 23 //if(nx >= 20 * L) nx = nx - 20 * L; 24 if(nx >= L) nx = 2 * L - nx; 25 } 26 while(R >= ny + EPS || ny - EPS >= W) { 27 if(R >= ny) ny = 2 * R - ny; 28 if(ny >= W) ny = 2 * W - ny; 29 } 30 printf("%.2f %.2f ", nx, ny); 31 } 32 }