2641:Billiard

keyword

平面幾何 反射 C++

概要

ビリヤード台の幅と高さが与えられる(穴は無い)。中心からショットして、s秒後に縦横の壁にそれぞれm,n回衝突して中心に戻ってくる(衝突は全て弾性衝突)。このときのショットの角度と速度を求める問題。
セオリー通り反射は反転させて考える。縦と横の壁にぶつかる順番は分からなくても最終的にどの位置に中心が写されるのかは定数時間で計算できる。
実装はいつもと違う感じで書いてみた。

double a, b;
int s, m, n;

inline int input(){
    scanf("%lf%lf%d%d%d",&a,&b,&s,&m,&n);
    return s;
}

inline void solve(){
    double th = atan2(b*n, a*m)*180/PI, dist = hypot(b*n,a*m);
    printf("%.2f %.2f\n", th+EPS, dist/s);
    return ;
}

int main(){

    while(input()){
        solve();
    }

    return 0;
}