fork download
  1. #include <cstdio>
  2. #include <vector>
  3. #include <cmath>
  4.  
  5. struct Point {
  6. double x, y;
  7.  
  8. Point (double x = 0, double y = 0) : x(x), y(y) { }
  9.  
  10. static Point read() {
  11. double x, y;
  12. scanf("%lf %lf", &x, &y);
  13. return Point(x, y);
  14. }
  15.  
  16. bool in_circle(const double r) const {
  17. return x*x+y*y < r*r;
  18. }
  19. };
  20.  
  21. Point operator -(const Point & left, const Point & right) {
  22. return Point(left.x-right.x, left.y-right.y);
  23. }
  24.  
  25. Point operator +(const Point & left, const Point & right) {
  26. return Point(left.x+right.x, left.y + right.y);
  27. }
  28.  
  29. Point operator *(const Point & left, const double right) {
  30. return Point(left.x * right, left.y * right);
  31. }
  32.  
  33. Point operator *(const double left, const Point & right) {
  34. return right * left;
  35. }
  36.  
  37. double det(const Point & left, const Point & right) {
  38. return left.x * right.y - left.y * right.x;
  39. }
  40.  
  41. struct Line {
  42. Point A, B;
  43.  
  44. Line (const Point & A = Point(), const Point & B = Point()) : A(A), B(B) { }
  45.  
  46. static Line read() {
  47. return Line(Point::read(), Point::read());
  48. }
  49.  
  50. Point intersect(const Line & other) const {
  51. return other.A + (other.B-other.A) * (det(other.A - A, B-A) / det(B-A, other.B-other.A));
  52. }
  53. };
  54.  
  55. int main() {
  56. //freopen("input.txt", "rt", stdin);
  57.  
  58. double r;
  59. int k;
  60. scanf("%lf %d", &r, &k);
  61.  
  62. int count = 1+k;
  63. std::vector<Line> v(k);
  64. for (int i = 0; i < (int) v.size(); ++i) {
  65. v[i] = Line::read();
  66. for (int j = 0; j < i; ++j) {
  67. count += v[i].intersect(v[j]).in_circle(r);
  68. }
  69. }
  70.  
  71. printf("%d", count);
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0s 4460KB
stdin
99.999999 2
-99.999999 0 99.999998 0.014142
-99.999998 0 99.999998 0.014142
stdout
4