UVa 11130 - Billiard bounces Solution

#include <iostream>
#include <cmath>
using namespace std;
int a,b,v,angl,s,ver,hor;
int main(){
    ios::sync_with_stdio(0);
    while(1){
        cin>>a>>b>>v>>angl>>s;
        if(!(a|b|v|angl|s))
            return 0;
        double angle=angl*3.14159265/180;
        double vx=v*cos(angle),vy=v*sin(angle);
        double dx=vx*s/2,dy=vy*s/2;
        if(dx<a/2)
            hor=0;
        else
            hor=1+(dx-double(a)/2)/a;
        if(dy<b/2)
            ver=0;
        else
            ver=1+(dy-double(b)/2)/b;
        cout<<hor<<' '<<ver<<endl;
    }
}

Comments