1000. Circle and Rectangle

Posted 任我主宰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1000. Circle and Rectangle相关的知识,希望对你有一定的参考价值。

#include<iostream>
#include<cmath>
using namespace std;

class Point{

private:

 double x,y;

public:

 Point();

 Point(double xv,double yv);

 Point(Point& pt);

 double getx();

 double gety();

};

Point::Point(){
 x=0;y=0;
}

Point::Point(double xv,double yv){
 x=xv;y=yv;
}

Point::Point(Point& pt){
 this->x = pt.x;
 this->y = pt.y;
}

double Point::getx(){
 return x;
}
double Point::gety(){
 return y;
}


class Circle : public Point{
 public:
  Circle(double x,double y,double r);
  Circle();
  Circle(Circle &);
     int position(Point &pr){
      double a = pow(pr.getx() - this->getx(),2) + pow(pr.gety() - this->gety(),2);
      if(a==r*r) return 0;
      if(a>r*r) return 1;
      if(a<r*r) return -1;
      }
    private:
     double r;
};

Circle::Circle(double x,double y,double r) : Point(x,y){
 this->r=r;
}

Circle::Circle() : Point(){
 r=0;
}

Circle::Circle(Circle &t) : Point(t.getx(),t.gety()){
 r = t.r;
}

class Rectangle : public Point{
 public:
  
     Rectangle(double x,double y,double len,double wid) : Point(x,y){
      this->len=len;
      this->wid=wid;
     }
     Rectangle();
  Rectangle(Rectangle &);
     int position(Point &pr){
      double a = pr.getx() - this->getx();
      double b = pr.gety() - this->gety();
//      cout<<a<<"KKKK"<<b<<endl;
//      if((a==0&&b<=wid&&b>0)||(a>0&&a<=len&&b==0)||(a==len&&b<=wid&&b>0)||(a>0&&a<=len&&b==wid)) return 0;
      if(a<len&&a>0&&b<wid&&b>0) return -1;
      else if(a>len||b>wid||a<0||b<0) return 1; //wai
      else return 0; //zai
      }
    private:
     double len;
     double wid;
};

Rectangle::Rectangle() : Point(){
 len=1;
 wid=1;
}
Rectangle::Rectangle(Rectangle &t): Point(t.getx(),t.gety()){
 len = t.len;
 wid = t.wid;
}

 

以上是关于1000. Circle and Rectangle的主要内容,如果未能解决你的问题,请参考以下文章

[CF1172B] Nauuo and Circle

CF1172B Nauuo and Circle

cf1173 D. Nauuo and Circle

002 -- Circle LinkList 3 -- Puzzels_Magic Poker and Latin

Codeforces 1372D Omkar and Circle

POJ - 1981 :Circle and Points (圆的扫描线) hihocoder1508