c_cpp 第三题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 第三题相关的知识,希望对你有一定的参考价值。
#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;
}
以上是关于c_cpp 第三题的主要内容,如果未能解决你的问题,请参考以下文章
第三题
20160317第三题
可信考试第三题-20220722
第三题数列求值
leetcode第三题
第三题(非实验5)