Advertisement
Stepavly

Untitled

Jul 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #pragma GCC optimize("O3")
  2. #pragma GCC target("tune=native")
  3. #pragma GCC optimize("fast-math,unroll-loops")
  4.  
  5. #include <math.h>
  6. #include <algorithm>
  7. #include <set>
  8. #include <iostream>
  9. #include <vector>
  10. #include <queue>
  11. #include <map>
  12. #include <string>
  13. #include <time.h>
  14. #include <cassert>
  15. #include <functional>
  16. #include <memory.h>
  17. #include <stack>
  18. #include <bitset>
  19. #include <unordered_map>
  20. #include <unordered_set>
  21. #include <random>
  22. #include <chrono>
  23. #include <complex>
  24. #include <fstream>
  25. #include <climits>
  26. using namespace std;
  27.  
  28. typedef unsigned long long ull;
  29. typedef long long ll;
  30. typedef unsigned u;
  31. typedef long double ld;
  32. typedef vector<vector<int>> vvi;
  33. typedef unsigned char uc;
  34. typedef unsigned short us;
  35. typedef complex<double> cd;
  36.  
  37. #define INF 1000000000
  38. #define LLINF 1000000000000000000LL
  39. #define EPS 1e-9l
  40. #define pii pair<int, int>
  41.  
  42. const int DEBUG = 0;
  43.  
  44. #ifdef LOCAL
  45. mt19937 gen(228);
  46. #else
  47. mt19937 gen((u)chrono::high_resolution_clock::now().time_since_epoch().count());
  48. #endif
  49.  
  50. #pragma comment(linker, "/STACK:76777216")
  51.  
  52. struct pt
  53. {
  54. double x, y;
  55.  
  56. pt()
  57. {
  58. x = y = 0;
  59. }
  60.  
  61. pt(double x, double y)
  62. : x(x), y(y)
  63. {}
  64. };
  65.  
  66. struct line
  67. {
  68. double a, b, c;
  69.  
  70. line()
  71. {
  72. a = b = c = 0;
  73. }
  74.  
  75. line(double a, double b, double c) : a(a), b(b), c(c) {}
  76.  
  77. line(pt p, pt q)
  78. {
  79. a = p.y - q.y;
  80. b = q.x - p.x;
  81. c = p.x * q.y - p.y * q.x;
  82.  
  83. double norm = sqrt(a * a + b * b);
  84.  
  85. a /= norm;
  86. b /= norm;
  87. c /= norm;
  88. }
  89.  
  90. line perp(pt p)
  91. {
  92. double a1 = -b;
  93. double b1 = a;
  94. double c1 = -a1 * p.x - b1 * p.y;
  95.  
  96. return line(a1, b1, c1);
  97. }
  98. };
  99.  
  100. pt intersect(line a, line b)
  101. {
  102. double x = (b.b * a.c - b.c * a.b) / (b.a * a.b - b.b * a.a);
  103. double y = (b.a * a.c - a.a * b.c) / (a.a * b.b - b.a * a.b);
  104.  
  105. return pt(x, y);
  106. }
  107.  
  108. int main()
  109. {
  110. ios_base::sync_with_stdio(0);
  111. cin.tie(0);
  112. cout.setf(cout.fixed);
  113. cout.precision(12);
  114. auto START_TIME = chrono::high_resolution_clock::now();
  115.  
  116. pt a, b, c;
  117. cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;
  118.  
  119. line l1(a, b);
  120. l1 = l1.perp(c);
  121.  
  122. line l2(b, c);
  123. l2 = l2.perp(a);
  124.  
  125. pt d = intersect(l1, l2);
  126.  
  127. cout << d.x << " " << d.y;
  128.  
  129. #ifdef LOCAL
  130. cerr.precision(3);
  131. cerr << "\nWorking time: " << chrono::duration<double>(chrono::high_resolution_clock::now() - START_TIME).count() << " sec.";
  132. #endif
  133.  
  134. return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement