Advertisement
a53

DistantaPunctSegment

a53
Apr 8th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #include <fstream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin ("distantapunctsegment.in");
  8. ofstream fout("distantapunctsegment.out");
  9.  
  10. int X1, Y1, X2, Y2, X3, Y3;
  11.  
  12. int det(int X1, int Y1, int X2, int Y2, int X3, int Y3) {
  13. return (X2-X1)*(Y3-Y1) - (X3-X1)*(Y2-Y1);
  14. }
  15.  
  16. int distantaPuncte(int X1, int Y1, int X2, int Y2) {
  17. return (X1-X2)*(X1-X2) + (Y1-Y2)*(Y1-Y2);
  18. }
  19.  
  20. int punctPeSegment(int x1, int y1, int x2, int y2, int x3, int y3) {
  21. int d = det(x1, y1, x2, y2, x3, y3);
  22. if (d!=0)
  23. return 0;
  24. if (x1 == x3 && y1 == y3)
  25. return 1;
  26. if (x2 == x3 && y2 == y3)
  27. return 1;
  28. if ((x3-x1) * (x3-x2) < 0 || (y3-y1) * (y3-y2) < 0)
  29. return 1;
  30. else
  31. return 0;
  32. }
  33.  
  34. int main() {
  35. fin>>X1>>Y1>>X2>>Y2>>X3>>Y3;
  36. int a = det(X1, Y1, X2, Y2, X3, Y3);
  37. if (a == 0) {
  38. if (punctPeSegment(X3, Y3, X2, Y2, X1, Y1)) {
  39. fout<<setprecision(2)<<fixed<< 0.0;
  40. } else {
  41. int d1 = distantaPuncte(X1, Y1, X2, Y2);
  42. int d2 = distantaPuncte(X1, Y1, X3, Y3);
  43. if (d1 < d2)
  44. fout<<setprecision(2)<<fixed<< (int)(sqrt(d1)*100)/100.0;
  45. else
  46. fout<<setprecision(2)<<fixed<< (int)(sqrt(d2)*100)/100.0;
  47. }
  48. return 0;
  49. }
  50.  
  51.  
  52. if (a < 0)
  53. a = -a;
  54. int d1 = distantaPuncte(X2, Y2, X3, Y3);
  55. int d2 = distantaPuncte(X1, Y1, X3, Y3);
  56. int d3 = distantaPuncte(X2, Y2, X1, Y1);
  57.  
  58. if (d2 < d1 + d3 && d3 < d1 + d2) {
  59. double h = a/sqrt(d1);
  60. fout<<setprecision(2)<<fixed<< (int)(h*100)/100.0;
  61. } else {
  62. int d1 = distantaPuncte(X1, Y1, X2, Y2);
  63. int d2 = distantaPuncte(X1, Y1, X3, Y3);
  64. if (d1 < d2)
  65. fout<<setprecision(2)<<fixed<< (int)(sqrt(d1)*100)/100.0;
  66. else
  67. fout<<setprecision(2)<<fixed<< (int)(sqrt(d2)*100)/100.0;
  68. }
  69.  
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement