Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define fori(n) for (int i = 0; i < (n); i++)
  4. #define forj(n) for (int j = 0; j < (n); j++)
  5. #define FOR(a,b,c) for (int a = (b); a < (c); ++a)
  6. #define forfill(n,x) for (int zzz = 0; zzz < (n); zzz++) cin >> x[zzz]
  7. #define all(x) (x).begin(), (x).end()
  8. #define allr(x) (x).rbegin(), (x).rend()
  9. #define unsync cin.sync_with_stdio(false), cin.tie(0)
  10. #define inoutfile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout)
  11. //scanf("%d",&n);
  12. #define INFINITY (1e+300*1e+300)
  13.  
  14. typedef long long lng;
  15. typedef pair<int, int> pii;
  16. typedef pair<lng, lng> pll;
  17. typedef vector<int> vi;
  18. typedef vector<vector<int>> vii;
  19. typedef vector<pair<int, int>> vpii;
  20. int a, b, c;
  21.  
  22. struct point {
  23. long long x, y;
  24. };
  25.  
  26. point start, endp;
  27.  
  28.  
  29. double dist(point a, point b) {
  30. double x = a.x - b.x;
  31. double y = a.y - b.y;
  32. return sqrt(x*x + y*y);
  33. }
  34.  
  35. int main()
  36. {
  37. scanf("%d%d%d", &a, &b, &c);
  38. scanf("%I64d %I64d %I64d %I64d", &(start.x), &(start.y), &(endp.x), &(endp.y));
  39.  
  40. point startLineV;
  41. point startLineX;
  42. point endLineV;
  43. point endLineX;
  44.  
  45. startLineV.x = start.x;
  46. startLineX.y = start.y;
  47.  
  48. endLineV.x = endp.x;
  49. endLineX.y = endp.y;
  50.  
  51.  
  52. double startToLineV = INFINITY, startToLineX = INFINITY, endToLineV = INFINITY, endToLineX = INFINITY;
  53.  
  54. startLineV.y = -c - a * startLineV.x;
  55. if (startLineV.y % b == 0) {
  56. startLineV.y /= b;
  57. startToLineV = dist(start, startLineV);
  58. }
  59. startLineX.x = -c - b * startLineX.y;
  60. if (startLineX.x % a == 0) {
  61. startLineX.x /= a;
  62. startToLineX = dist(start, startLineX);
  63. }
  64. endLineV.y = -c - a * endLineV.x;
  65. if (endLineV.y % b == 0) {
  66. endLineV.y /= b;
  67. endToLineV = dist(endp, endLineV);
  68. }
  69. endLineX.x = -c - b * endLineX.y;
  70. if (endLineX.x % a == 0) {
  71. endLineX.x /= a;
  72. endToLineX = dist(endp, endLineX);
  73. }
  74.  
  75. double v[] = {
  76. startToLineV + endToLineV + dist(startLineV, endLineV),
  77. startToLineX + endToLineV + dist(startLineX, endLineV),
  78. startToLineV + endToLineX + dist(startLineV, endLineX),
  79. startToLineX + endToLineX + dist(startLineX, endLineX),
  80. abs(start.x -endp.x)+abs(start.y-endp.y)
  81. };
  82.  
  83. printf("%.8lf", *min_element(v, v + 5));
  84. //y=(-c-ax)/b
  85. //ax+by+c=0.
  86. //printf("%d\n", stolen)
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement