Time Limit: 1000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
Description
Ball in a Rectangle
Input: Standard Input Output: Standard Output
Ball in a Rectangle |
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 .Sample Input
100 100 80 10 5 90 2 23 110 100 70 10 5 180 1 9999 0 0 0 0 0 0 0 0
Sample Output
80.00 56.00 71.00 10.00
Problemsetter: Rujia Liu, Special Thanks: Yiming Li, Shamim Hafiz & Sohel Hafiz
题解:给定一个左下角和坐标重合的矩形,和一个半径为r的圆,圆心在(x,y)处,给定一个速度和角度,问s秒后,这个圆运动到哪里了,碰撞时和光线入射反射一样,切速度不变
题解:明显这相当于一个点在(r,r)到(l-r,w-r)这个矩形内运动,然后仔细观察就会发觉x和y坐标的速度是永远不变的,而且是x方向运动和y方向运动是互相分离的,那么就可以当它拼命在往回运动。然后沿它运动方向作一条路径的线段,假设它可以这样运动,然后把线段按出界点翻折,不断作这个动作,直到坐标在上述矩形内即可,y坐标也如此
#include<stdio.h>
#include<math.h>
const double eps=1e-8;
const double pi=2*asin(1.0);
int main()
{
double l,w,x,y,r,a,v,s;
double px,py;
while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&l,&w,&x,&y,&r,&a,&v,&s),r!=0)
{
l-=r,w-=r;
px=x+v*cos(a/180*pi)*s;
py=y+v*sin(a/180*pi)*s;
while(r-px>eps||px-l>eps)
{
if(r-px>eps) px=(r-px)+r;
else px=-(px-l)+l;
}
while(r-py>eps||py-w>eps)
{
if(r-py>eps) py=(r-py)+r;
else py=-(py-w)+w;
}
printf("%.2lf %.2lf\n",px,py);
}
return 0;
}