fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5. double distance (double x1,double x2,double y1,double y2)
  6. {
  7. return (sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
  8. }
  9. int main() {
  10. cout.precision(2);
  11. double a, b, c;
  12. cin>>a>>b>>c;
  13. double x2, y2, x1, y1, z2;
  14. cin>>x1>>y1;
  15. cin>>x2>>y2>>z2;
  16. double s=250000000;
  17. if (z2==0) s=distance (x1,x2,y1,y2);//"floor" case
  18. else
  19. {
  20. if (x2==0) {x2=-z2; s=distance (x1,x2,y1,y2);}//"left wall" case
  21. if (x2==a) {x2=a+z2; s=distance (x1,x2,y1,y2);}//"right wall" case
  22. if (y2==0) {y2=-z2; s=min(s, distance (x1,x2,y1,y2));}//"near wall" case
  23. if (y2==b) {y2=b+z2; s=min(s, distance (x1,x2,y1,y2));}//"distant wall" case
  24. }
  25. cout<<fixed<<s;
  26. return 0;
  27. }
Success #stdin #stdout 0s 4504KB
stdin
5 5 5 
3 4 0 0 0
stdout
5.00