Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <iomanip>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <cassert>
  7.  
  8.  
  9. using namespace std;
  10.  
  11. typedef long double T;
  12.  
  13. const T EPS = 1e-9;
  14.  
  15. struct Point {
  16. Point(T x_, T y_) : x(x_), y(y_) {}
  17. Point() {}
  18. Point& operator=(const Point& p) {
  19. x = p.x;
  20. y = p.y;
  21. return *this;
  22. }
  23. T x;
  24. T y;
  25. };
  26.  
  27.  
  28. Point operator+ (const Point& p1, const Point& p2) {
  29. return Point(p1.x + p2.x, p1.y + p2.y);
  30. }
  31.  
  32. Point operator- (const Point& p1, const Point& p2) {
  33. return Point(p1.x - p2.x, p1.y - p2.y);
  34. }
  35.  
  36. T operator^ (const Point& p1, const Point& p2) {
  37. return p1.x * p2.x + p1.y * p2.y;
  38. }
  39.  
  40. T operator* (const Point& p1, const Point& p2) {
  41. return p1.x * p2.y - p1.y * p2.x;
  42. }
  43.  
  44. Point operator*(const Point& p1, T c) {
  45. return Point(p1.x * c, p1.y * c);
  46. }
  47.  
  48. Point operator*(T c, const Point& p1) {
  49. return Point(p1.x * c, p1.y * c);
  50. }
  51.  
  52. bool isZero(T x) {
  53. return fabsl(x) < EPS;
  54. }
  55.  
  56. bool areEqual(T x, T y) {
  57. return isZero(x - y);
  58. }
  59.  
  60. bool isLessThan(T x, T y) {
  61. return (x - y) < (-1 * EPS);
  62. }
  63.  
  64. bool isMoreThan(T x, T y) {
  65. return (x - y) > EPS;
  66. }
  67.  
  68. bool isNoLessThan(T x, T y) {
  69. return !isLessThan(x, y);
  70. }
  71.  
  72. bool isNoMoreThan(T x, T y) {
  73. return !isMoreThan(x, y);
  74. }
  75.  
  76. T len2(const Point& p) {
  77. return p.x * p.x + p.y * p.y;
  78. }
  79.  
  80. bool areEqual(const Point& p1, const Point& p2) {
  81. return areEqual(p1.x, p2.x) && areEqual(p1.y, p2.y);
  82. }
  83.  
  84. bool areCollinear(const Point& p1, const Point& p2) {
  85. return isZero(p1 * p2);
  86. }
  87.  
  88. bool areCodirected(const Point& p1, const Point& p2) {
  89. return areCollinear(p1, p2) && isNoLessThan(p1 ^ p2, 0);
  90. }
  91.  
  92. bool isOnLine(const Point& a, const Point& b, const Point& c) {
  93. return areCollinear(b - a, c - a);
  94. }
  95.  
  96. bool isOnSegment(const Point& a, const Point& b, const Point& c) {
  97. return areCodirected(a - b, c - a);
  98. }
  99.  
  100. Point findLinesIntersection(const Point& a, const Point& b, const Point& c, const Point& d) {
  101. T t = ((c - a) * (d - c)) / ((b - a) * (d - c));
  102. return a + (t * (b - a));
  103. }
  104.  
  105.  
  106. int main() {
  107. cout << setprecision(20);
  108.  
  109. long double x0;
  110. int w = 0;
  111. while (cin >> x0) {
  112. if (w != 0) {
  113. cout << endl;
  114. }
  115. w++;
  116. long double y0, r, x1, y1, x2, y2;
  117. cin >> y0 >> r >> x1 >> y1 >> x2 >> y2;
  118. auto a = Point(x0, y0);
  119. auto b = Point(x1, y1);
  120. auto c = Point(x2, y2);
  121. b = b - a;
  122. c = c - a;
  123. if (r == 0) {
  124. if ((x1 == x2) && (y1 == y2)) {
  125. if ((x1 == x0) && (y1 == y0)) {
  126. cout << 1 << endl;
  127. cout << x0 << " " << y0 << endl;
  128. } else {
  129. cout << 0 << endl;
  130. }
  131. } else {
  132. if (isOnSegment(Point(0, 0), b, c)) {
  133. cout << 1 << endl;
  134. cout << x0 << " " << y0 << endl;
  135. } else {
  136. cout << 0 << endl;
  137. }
  138. }
  139. continue;
  140. }
  141. if (x1 == x2 && y1 == y2) {
  142. if (areEqual(len2(b), r * r)) {
  143. cout << 1 << endl;
  144. cout << x1 << " " << y1 << endl;
  145. } else {
  146. cout << 0 << endl;
  147. }
  148. continue;
  149. }
  150. /////////////////
  151. Point a1 = b - c;
  152. Point b1 = c;
  153. long double desc = (a1 ^ b1) * (a1 ^ b1) - (a1 ^ a1) * ((b1 ^ b1) - r * r);
  154. if (desc < -EPS) {
  155. cout << 0 << endl;
  156. } else if (areEqual(desc, 0)) {
  157. long double t = (-1) * (a1 ^ b1) / (a1 ^ a1);
  158. Point ans = b * t + (1 - t) * c;
  159. if (((0 - EPS) <= t) && (t <= 1 + EPS)) {
  160. cout << 1 << endl;
  161. cout << (ans.x + a.x) << " " << (ans.y + a.y) << endl;
  162. } else {
  163. cout << 0 << endl;
  164. }
  165. } else {
  166. long double t1 = (((-1) * (a1 ^ b1)) + sqrtl(desc)) / (a1 ^ a1);
  167. long double t2 = (((-1) * (a1 ^ b1)) - sqrtl(desc)) / (a1 ^ a1);
  168. Point ans1 = b * t1 + (1 - t1) * c;
  169. Point ans2 = b * t2 + (1 - t2) * c;
  170. if (len2(ans1 - ans2) <= EPS) {
  171. cout << 1 << endl;
  172. cout << ans1.x + a.x << " " << ans1.y + a.y << endl;
  173. continue;
  174. }
  175. if (((0 - EPS) <= t1) && (t1 <= 1 + EPS)) {
  176. if (((0 - EPS) <= t2) && (t2 <= 1 + EPS)) {
  177. bool ord = ans1.x == ans2.x ? ans1.y < ans2.y : ans1.x < ans2.x;
  178. if (ord) {
  179. cout << 2 << endl;
  180. cout << (ans1.x + a.x) << " " << (ans1.y + a.y) << endl;
  181. cout << (ans2.x + a.x) << " " << (ans2.y + a.y) << endl;
  182. } else {
  183. cout << 2 << endl;
  184. cout << (ans2.x + a.x) << " " << (ans2.y + a.y) << endl;
  185. cout << (ans1.x + a.x) << " " << (ans1.y + a.y) << endl;
  186. }
  187. } else {
  188. cout << 1 << endl;
  189. cout << (ans1.x + a.x) << " " << (ans1.y + a.y) << endl;
  190. }
  191. } else {
  192. if (((0 - EPS) <= t2) && (t2 <= 1 + EPS)) {
  193. cout << 1 << endl;
  194. cout << (ans2.x + a.x) << " " << (ans2.y + a.y) << endl;
  195. } else {
  196. cout << 0 << endl;
  197. }
  198. }
  199. }
  200. }
  201. return 0;
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement