有個坑是: Problem E: 點在圓內嗎? Problem E: 點在圓內嗎? Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 553 Solved: 277[Submit][Status][Web Board] Description 定義一個Poi ...
有個坑是:
- The Point (0, 0) is created!
- A Point (0, 0) is copied!
- A Point (0, 0) is erased!
Home | Web Board | ProblemSet | Standing | Status | Statistics |
Problem E: 點在圓內嗎?
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 553 Solved: 277
[Submit][Status][Web Board]
Description
定義一個Point類和Circle類,用於判斷給定的一系列的點是否在給定的圓內。
其中,Point類:
1.有2個成員x和y,分別為其橫坐標和縱坐標;1個靜態成員numOfPoints,用於計算生成的點的個數。
2.具有構造函數、析構函數和拷貝構造函數,具體格式輸出根據樣例自行判斷。
3. 具有靜態方法int getNumOfPoints(),用於返回numOfPoints的值。
4. 具有int getX()和int getY()方法,用於獲取橫坐標和縱坐標。
Circle類:
1. 擁有Point類的對象center,表示圓心坐標。擁有radius對象,表示圓的半徑;1個靜態成員numOfCircles,用於指示生成了多少個圓對象。
2. 具有構造函數、析構函數和拷貝構造函數,具體格式根據樣例自行判斷。
3.具有靜態方法int getNumOfCircles(),返回numOfCircles的值。
4. 具有getCenter()方法,返回圓心坐標。註意:根據輸出結果判斷返回值類型。
5. 具有bool pointInCircle(Point &)方法,用於判斷給定的點是否在當前圓內。是則返回true,否則返回false。
Input
輸入分多行。
第一行M>0,表示有M個測試用例。
每個測試用例又包括多行。第1行包含3個整數,分別為一個圓的橫坐標、縱坐標和半徑。第2行N>0,表示之後又N個點,每個點占一行,分別為其橫坐標和縱坐標。
所有輸入均為整數,且在int類型範圍內。
Output
輸出見樣例。註意:在圓的邊上的點,不在圓內。
Sample Input
2 0 0 10 3 2 2 11 11 10 0 1 1 20 3 2 2 1 1 100 100Sample Output
The Point (0, 0) is created! Now, we have 1 points. The Point (1, 1) is created! Now, we have 2 points. A circle at (1, 1) and radius 1 is created! Now, we have 1 circles. We have 2 points and 1 circles now. The Point (0, 0) is created! Now, we have 3 points. A Point (0, 0) is copied! Now, we have 4 points. A Point (0, 0) is copied! Now, we have 5 points. A circle at (0, 0) and radius 10 is created! Now, we have 2 circles. A Point (0, 0) is erased! Now, we have 4 points. The Point (2, 2) is created! Now, we have 5 points. (2, 2) is in the circle at (0, 0). The Point (11, 11) is created! Now, we have 6 points. (11, 11) is not in the circle at (0, 0). The Point (10, 0) is created! Now, we have 7 points. (10, 0) is not in the circle at (0, 0). A Point (0, 0) is erased! Now, we have 6 points. A circle at (0, 0) and radius 10 is erased! Now, we have 1 circles. A Point (0, 0) is erased! Now, we have 5 points. The Point (1, 1) is created! Now, we have 6 points. A Point (1, 1) is copied! Now, we have 7 points. A Point (1, 1) is copied! Now, we have 8 points. A circle at (1, 1) and radius 20 is created! Now, we have 2 circles. A Point (1, 1) is erased! Now, we have 7 points. The Point (2, 2) is created! Now, we have 8 points. (2, 2) is in the circle at (1, 1). The Point (1, 1) is created! Now, we have 9 points. (1, 1) is in the circle at (1, 1). The Point (100, 100) is created! Now, we have 10 points. (100, 100) is not in the circle at (1, 1). A Point (1, 1) is erased! Now, we have 9 points. A circle at (1, 1) and radius 20 is erased! Now, we have 1 circles. A Point (1, 1) is erased! Now, we have 8 points. We have 8 points, and 1 circles. A circle at (1, 1) and radius 1 is erased! Now, we have 0 circles. A Point (1, 1) is erased! Now, we have 7 points. A Point (0, 0) is erased! Now, we have 6 points.HINT
Append Code
append.cc,
한국어<
中文
فارسی
English
ไทย
All Copyright Reserved 2010-2011 SDUSTOJ TEAM
GPL2.0 2003-2011 HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin
#include<iostream> using namespace std; class Point{ public: int x,y; static int numOfPoints; Point(int a=0,int b=0):x(a),y(b){numOfPoints++;cout<<"The Point ("<<x<<", "<<y<<") is created! Now, we have "<<numOfPoints<<" points."<<endl;} ~Point(){numOfPoints--;cout<<"A Point ("<<x<<", "<<y<<") is erased! Now, we have "<<numOfPoints<<" points."<<endl;} Point(const Point&p){numOfPoints++;x=p.x;y=p.y;cout<<"A Point ("<<x<<", "<<y<<") is copied! Now, we have "<<numOfPoints<<" points."<<endl;} static int getNumOfPoints(){return numOfPoints;} int getX(){return x;} int getY(){return y;} }; class Circle{ public: Point center; int radius; static int numOfCircles; Circle(int a,int b,int c):center(a,b),radius(c){numOfCircles++;cout<<"A circle at ("<<center.x<<", "<<center.y<<") and radius "<<radius<<" is created! Now, we have "<<numOfCircles<<" circles."<<endl;} Circle(Point p,int r):center(p),radius(r){numOfCircles++;cout<<"A circle at ("<<center.x<<", "<<center.y<<") and radius "<<radius<<" is created! Now, we have "<<numOfCircles<<" circles."<<endl;} ~Circle(){numOfCircles--;cout<<"A circle at ("<<center.x<<", "<<center.y<<") and radius "<<radius<<" is erased! Now, we have "<<numOfCircles<<" circles."<<endl;} Circle(const Circle &c){numOfCircles++;center.x=c.center.x;center.y=c.center.y;radius=c.radius;cout<<"A circle at ("<<center.x<<", "<<center.y<<") and radius "<<radius<<" is created! Now, we have "<<numOfCircles<<" circles."<<endl;} static int getNumOfCircles(){return numOfCircles;} Point &getCenter(){return center;} bool pointInCircle(Point &p){if((p.x-center.x)*(p.x-center.x)+(p.y-center.y)*(p.y-center.y)<radius*radius) return true;else return false;} }; int Point::numOfPoints=0; int Circle::numOfCircles=0; int main() { int cases,num; int x, y, r, px, py; Point aPoint(0,0), *bPoint; Circle aCircle(1,1,1); cin>>cases; cout<<"We have "<<Point::getNumOfPoints()<<" points and "<<Circle::getNumOfCircles()<<" circles now."<<endl; for (int i = 0; i < cases; i++) { cin>>x>>y>>r; bPoint = new Point(x,y); Circle circle(*bPoint, r); cin>>num; for (int j = 0; j < num; j++) { cin>>px>>py; if (circle.pointInCircle(*(new Point(px, py)))) { cout<<"("<<px<<", "<<py<<") is in the circle at ("; cout<<circle.getCenter().getX()<<", "<<circle.getCenter().getY()<<")."<<endl; } else { cout<<"("<<px<<", "<<py<<") is not in the circle at ("; cout<<circle.getCenter().getX()<<", "<<circle.getCenter().getY()<<")."<<endl; } } delete bPoint; } cout<<"We have "<<Point::getNumOfPoints()<<" points, and "<<Circle::getNumOfCircles()<<" circles."<<endl; return 0; }