Guest User

Untitled

a guest
Dec 14th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. class Point{
  6. public:
  7. double x, y;
  8. Point(double a, double b): x(a), y(b) {}
  9. Point(const Point& p) {
  10. x = p.x;
  11. y = p.y;
  12. }
  13. void setx(int a) { x = a; }
  14. void sety(int b) { y = b; }
  15. double getx() { return x; }
  16. double gety() { return y; }
  17. };
  18.  
  19. class Circle{
  20. private:
  21. Point coord;
  22. double r;
  23. public:
  24. Circle(Point p, double a): coord(p), r(a) {}
  25. int JudgeRelation(const Circle& another) {
  26. double d1 = r + another.r, d2 = fabs(r - another.r);
  27. double x1 = coord.x, y1 = coord.y;
  28. double x2 = another.coord.x, y2 = another.coord.y;
  29. if ( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) > d1*d1 ) return 1;
  30. if ( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) < d2*d2 ) return 2;
  31. if ( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) == d1*d1 ) return 3;
  32. if ( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) == d2*d2 ) return 4;
  33. if ( ((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) < d1*d1) && ((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) > d2*d2)) return 5;
  34.  
  35. }
  36. };
  37.  
  38. int main()
  39. {
  40. int t, r, d, n;
  41. int x, y;
  42. cin >> t;
  43. while(t--) {
  44. cin >> r >> d;
  45. Point p(0,0);
  46. Circle c1(p,r);
  47. Circle c2(p,d);
  48. cin >> n;
  49. int cnt = 0;
  50. for(int i = 0; i < n; ++i) {
  51. cin >> x >> y >> r;
  52. Circle c3(Point(x,y),r);
  53. int flag1 = c1.JudgeRelation(c3);
  54. int flag2 = c2.JudgeRelation(c3);
  55. if((flag1 == 2 || flag1 == 4 ) && (flag2 == 1 || flag2 == 3)) cnt++;
  56. }
  57. cout << cnt << endl;
  58. }
  59. return 0;
  60. }
Add Comment
Please, Sign In to add comment