Problem E: 点在圆内吗?

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 100

Sample 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

#include<iostream>

using namespace std;

class Point

{

private:

    int x,y;

    static int numOfPoints;

public:

    Point(int a,int b):x(a),y(b){numOfPoints++;cout<<"The Point ("<<x<<", "<<y<<") is created! Now, we have "<<numOfPoints<<" points.\n";}

    ~Point(){numOfPoints--;cout<<"A Point ("<<x<<", "<<y<<") is erased! Now, we have "<<numOfPoints<<" points.\n";}

    Point(const Point &q):x(q.x),y(q.y){numOfPoints++;cout<<"A Point ("<<x<<", "<<y<<") is copied! Now, we have "<<numOfPoints<<" points.\n";}

    static int getNumOfPoints(){return numOfPoints;}

    int getX(){return x;}

    int getY(){return y;}

};

int Point::numOfPoints=0;

class Circle

{

private:

    Point center;

    int radius;

    static int numOfCircles;

public:

    Circle(Point b,int a):center(b),radius(a){numOfCircles++;cout<<"A circle at ("<<center.getX()<<", "<<center.getY()<<") and radius "<<radius<<" is created! Now, we have "<<numOfCircles<<" circles.\n";}

    Circle(int a,int b,int c):center(a,b),radius(c){numOfCircles++;cout<<"A circle at ("<<center.getX()<<", "<<center.getY()<<") and radius "<<radius<<" is created! Now, we have "<<numOfCircles<<" circles.\n";}

    ~Circle(){numOfCircles--;cout<<"A circle at ("<<center.getX()<<", "<<center.getY()<<") and radius "<<radius<<" is erased! Now, we have "<<numOfCircles<<" circles.\n";}

   static int getNumOfCircles(){return numOfCircles;}

    Point &getCenter(){return center;}

    bool pointInCircle(Point &q)

    {

        int b=(q.getX()-center.getX())*(q.getX()-center.getX())+(q.getY()-center.getY())*(q.getY()-center.getY());

        if(b<radius*radius)

            return 1;

        return 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;

}

时间: 2024-10-14 01:46:17

Problem E: 点在圆内吗?的相关文章

如何检测一个圆在多个圆内?

问题定义: 存在多个半径相同的圆,和一个半径不同的圆,如何判断半径不同的圆完全在一群圆内.下图演示了几种情况,左边是完全在圆内,右边不是. 解决方法之一: 对于红圆在某个黑圆之内或者在所有黑圆之外等的特例情形,可以用简单的圆圆之间的几何判断算法得到结果,对于其余部分相交的一般情形,如果同时满足以下两个条件则红圆在黑圆内: 1. 红圆与所有黑圆的交点都在黑圆内: 2. 黑圆之间的交点如果在红圆内,则其也必然在黑圆内. 否则,红圆不在黑圆内.

圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point

1 // 圆内,求离圆心最远的整数点 hiho一下第111周 Farthest Point 2 // 思路:直接暴力绝对T 3 // 先确定x范围,每个x范围内,离圆心最远的点一定是y轴两端的点.枚举x的范围,再比较y 4 // O(n) 5 6 #include <bits/stdc++.h> 7 using namespace std; 8 #define LL long long 9 const double inf = 123456789012345.0; 10 const LL MO

判断一个点是否在圆内

/* * 判断一个点是不是在圆内 *  *  */public class Demo { public static void main(String[] args) {  //提示用户定义圆形和半径  Scanner sc = new Scanner(System.in);  //请输入圆形坐标  System.out.println("请输入圆心坐标:");  double a1 = sc.nextDouble();  double a2 = sc.nextDouble();   

圆内三角形统计

[题目描述] 在一个圆的圆周上有N(N <= 100)个点,用线段将它们彼此相连,任意三条线段在圆内都没有公共交点,询问这些线段能构成多少个顶点在圆内的三角形. [输入描述] 输入一个正整数N. [输出描述] 输出一个数表示答案. [样例输入] 6 [样例输出] 1

限定pan手势只能在圆内移动view

效果: 虽然看起来很简单,但实现原理还是稍微有点复杂-_-!! 核心的地方,就是需要计算pan手势的点与指定点的距离,不能超过这个距离,超过了就让动画还原,很容易理解:) // // RootViewController.m // Circle // // Copyright (c) 2014年 Y.X. All rights reserved. // #import "RootViewController.h" @interface RootViewController () @en

CODEVS1056 圆内三角形统计(大水题!!!)

题目描述:圆周上有N(N<=100)个点,用线段将它们彼此相连.这些线段中任意三条在圆内都没有公共交点,问这些线段能构成多少个顶点在圆内的三角形? 思路:坑死我吧!!!我苦心孤诣,刻苦钻研了半个小时...结果就是一个简单的c(6,n)...每一个园内三角形的三边都是圆上不同的点,所以就是从n个点钟取6个的组合数... 之所以写这道题,是因为这种简单而又神奇的思路能解决好多问题...看来我要好好学习了!!! code: #include<iostream> #include<cstd

ArcGIS API for Javascript 使用query查询以某个点为半径的圆内的要素出现“esri.config.defaults.io.proxyUrl 尚未进行设置”错误

当使用Query查询时,会用如下配置 var queryTask = new esri.tasks.QueryTask(applicationModelOneSearchPOIURL); var query = new esri.tasks.Query(); query.geometry = geometry; query.outSpatialReference = map.spatialReference; query.spatialRelationship = esri.tasks.Quer

【TOJ 5276】圆内交点

描述 现在有一个很大的圆,圆周上有N个互不重合的点,让这N个点两两连线,问连线有多少条,这些连线在圆的内部有多少个交点. 输入 多组输入,每行输入一个数字表示N(1 ≤ N ≤ 100); 输出 输出两个数字,第一个数字表示连线的条数,第二个数字表示园内交点的个数. 样例输入 24 样例输出 1 06 1 #include<bits/stdc++.h> double lncom(int n,int m) //在c语言中,log函数也就是我们通常所说的ln函数,即以e为底的对数函数 { doub

[Swift]LeetCode478. 在圆内随机生成点 | Generate Random Point in a Circle

Given the radius and x-y positions of the center of a circle, write a function randPoint which generates a uniform random point in the circle. Note: input and output values are in floating-point. radius and x-y position of the center of the circle is