fork download
  1. #include <iostream>
  2. #include <assert.h>
  3. #include <math.h>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.  
  10. long double x,y,va,vb;
  11.  
  12. cin >> x >> y >> va >> vb;
  13.  
  14. if(x < 1) { cout << "Invalid Input"; return 0; }
  15. if(y < 1) { cout << "Invalid Input"; return 0; }
  16. if(va < 1) { cout << "Invalid Input"; return 0; }
  17. if(vb < 1) { cout << "Invalid Input"; return 0; }
  18.  
  19. long double t = (x*va + y*vb)/(pow(va,2.00000000000) + pow(vb,2.00000000000));
  20.  
  21. long double diff = (pow((x-t*va),2.00000000000)) + (pow((y-t*vb),2.00000000000));
  22.  
  23. long double fa = sqrt(diff);
  24.  
  25. if(fa == 0) {
  26. cout << "0.0";
  27. }
  28. else {
  29. cout << setprecision(13) << fa << endl;
  30. }
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 3464KB
stdin
500
300
20
14
stdout
40.96159602595