toj 4608 Ball in a Rectangle

来源:互联网 发布:ojbdk是什么意思网络 编辑:程序博客网 时间:2024/05/17 14:25

toj 4608 Ball in a Rectangle


时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte
总提交: 26 测试通过:16

描述

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?

输入

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.

输出

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.

样例输入

100 100 80 10 5 90 2 23
110 100 70 10 5 180 1 9999
0 0 0 0 0 0 0 0

样例输出

80.00 56.00
71.00 10.00

//矢量分解#include <iostream>#include <cstdio>#include <cmath>using namespace std;double l,w,x,y,r,a,v,s;int main(){    while(cin>>l>>w>>x>>y>>r>>a>>v>>s)    {        if(!l&&!w&&!x&&!y&&!r&&!a&&!v&&!s) break;        l-=2*r;w-=2*r;        x-=r;y-=r;//相应坐标也要变换        a=a*acos(0.0)/90;        double vx=v*cos(a),vy=v*sin(a);        double dx=fmod(fmod(vx*s,2*l)+2*l,2*l);//其实包括了两部分,向正方向和向负方向,为了code的方便,把两种情况统一为向正方向。                                               //fmod(vx*s,2*l)如果为负值,说明是向着负方向走i米,也就相当于向着正方向走了(2*l-i)米        double dy=fmod(fmod(vy*s,2*w)+2*w,2*w);        if(x+dx<=l) x+=dx;//分三种情况讨论        else if(x+dx<=2*l) x=l-(x+dx-l);        else x=x+dx-2*l;        if(y+dy<=w) y+=dy;        else if(y+dy<=2*w) y=w-(y+dy-w);        else y=y+dy-2*w;        printf("%.2lf %.2lf\n",x+r,y+r);    }    return 0;}
0 0