Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- class Point{
- public:
- double x, y;
- Point(double a, double b): x(a), y(b) {}
- Point(const Point& p) {
- x = p.x;
- y = p.y;
- }
- void setx(int a) { x = a; }
- void sety(int b) { y = b; }
- double getx() { return x; }
- double gety() { return y; }
- };
- class Circle{
- private:
- Point coord;
- double r;
- public:
- Circle(Point p, double a): coord(p), r(a) {}
- int JudgeRelation(const Circle& another) {
- double d1 = r + another.r, d2 = fabs(r - another.r);
- double x1 = coord.x, y1 = coord.y;
- double x2 = another.coord.x, y2 = another.coord.y;
- if ( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) > d1*d1 ) return 1;
- if ( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) < d2*d2 ) return 2;
- if ( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) == d1*d1 ) return 3;
- if ( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) == d2*d2 ) return 4;
- if ( ((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) < d1*d1) && ((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) > d2*d2)) return 5;
- }
- };
- int main()
- {
- int t, r, d, n;
- int x, y;
- cin >> t;
- while(t--) {
- cin >> r >> d;
- Point p(0,0);
- Circle c1(p,r);
- Circle c2(p,d);
- cin >> n;
- int cnt = 0;
- for(int i = 0; i < n; ++i) {
- cin >> x >> y >> r;
- Circle c3(Point(x,y),r);
- int flag1 = c1.JudgeRelation(c3);
- int flag2 = c2.JudgeRelation(c3);
- if((flag1 == 2 || flag1 == 4 ) && (flag2 == 1 || flag2 == 3)) cnt++;
- }
- cout << cnt << endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment