24h購物| | PChome| 登入
2014-02-17 21:35:25| 人氣1,321| 回應0 | 上一篇 | 下一篇

[UVA] 11880 - Ball in a Rectangle

推薦 0 收藏 0 轉貼0 訂閱站台


  Ball in a Rectangle 

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

epsfbox{p11880.eps}

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 (100$ le$L,W$ le$109, 1$ le$R$ le$5, R$ le$x$ le$L - R, R$ le$y$ le$W - R, 0$ le$a < 360, 1$ le$v, s$ le$109), 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




題目描述:


求球在矩形內部的彈性碰撞後 s 秒後的位置。

題目解法:

忽略外框不計,最後再用取模和奇偶性質還原。

#include <stdio.h>
#include <math.h>
int main() {
    const double pi = acos(-1);
    double L, W, x, y, R, a, v, s;
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
            &L, &W, &x, &y, &R, &a, &v, &s) == 8) {
        if(R == 0)
            continue;
        L -= 2 * R;
        W -= 2 * R;
        double theta = a / 180.0 * pi;
        x -= R;
        y -= R;
        x = x + v * cos(theta) * s;
        y = y + v * sin(theta) * s;
        //printf("%lf %lf \n", x, y);
        if((((int)ceil((x / L))) %2+2)%2 == 0)
            x = L - fmod(x, L);
        else
            x = fmod(x, L);
        if((((int)ceil((y / W))) %2+2)%2 == 0)
            y = W - fmod(y, W);
        else
            y = fmod(y, W);
        x = fmod(x+L, L);
        y = fmod(y+W, W);
        printf("%.2lf %.2lf\n", x + R, y + R);
    }
    return 0;
}

台長: Morris
人氣(1,321) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA][遞迴] 10795 - A Different Task
此分類上一篇:[UVA][五則運算、貪婪] 11890 - Calculus Simplified

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文