toj 4608 Ball in a Rectangle
2016-08-09 11:39
281 查看
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![](http://acm.tzc.edu.cn/acmhome/judge/images/4608.jpg)
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 (100≤L,W≤109, 1≤R≤5, R≤x≤L - R, R≤y≤W - R, 0≤a < 360, 1≤v, s≤109), 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 23110 100 70 10 5 180 1 9999
0 0 0 0 0 0 0 0
样例输出
80.00 56.0071.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; }
相关文章推荐
- uva 11880 Ball in a Rectangle(计算几何)
- UVA 11880 (Ball in a Rectangle) 平面几何
- UVA 11880 Ball in a Rectangle 几何
- UVA 11880 Ball in a Rectanglefds
- UVA 11880 Ball in a Rectangle(数学+平面几何)
- D - Ball in a Rectangle
- UVA11880 Ball in a Rectangle
- hdoj-1506-Largest Rectangle in a Histogram【动态规划】
- hdu Largest Rectangle in a Histogram
- POJ 2559 Largest Rectangle in a Histogram -- 动态规划
- LeetCode Largest Rectangle in Histogram (单调栈)
- 暑期dp46道(8)--HDOJ 1506 Largest Rectangle in a Histogram
- POJ 2599 Largest Rectangle in a Histogram(DP&单调栈)
- 直方图最大矩形问题(Largest Rectangle in Histogram)
- LeetCode OJ --问题与解答 Largest Rectangle in Histogram
- [week 6] [Leetcode] Largest Rectangle in Histogram
- hdu 5391 Zball in Tina Town
- HDOJ 1506 Largest Rectangle in a Histogram
- 84:Largest Rectangle in Histogram【数组】【栈】
- hdu 5391 Zball in Tina Town 威尔逊定理