UVa 10773 – Back to Intermediate Math

#include <iostream>
#include <string>
#include <cmath>
#include <stdio.h>

using namespace std;

int main (){

	int n,t=0;
	double d,u,v,ans;
	cin>>n;

	std::cout.setf(std::ios::fixed);
	std::cout.precision(3);

	while (t++<n){
		cin>>d>>v>>u;
		ans = u*u - v*v ;
		if (ans<0.001||u<0.001||v<0.001)
           //cases that make the eqn of ans contains a NaN || d=0
			cout<<"Case "<< t <<": can't determine"<<endl;

		else {
			ans = d/sqrt(ans) -  d/u;
           //d/sqrt(u*u - v*v) = stearing with -ve angle so that the flow takes the boat to the destination
			cout<<"Case "<< t <<": "<< ans << endl;
		}
	}

	return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s