Advertisement
DarknessRdg

Kepler

Sep 2nd, 2019
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. float absoluto(float x) {
  6.     if (x < 0)
  7.         return -x;
  8.     else
  9.         return x;
  10. }
  11.  
  12. class Circulo {
  13.     float x; float y; float r;
  14.    
  15.     public:
  16.         Circulo(float x, float y, float r) {
  17.             this->x = x; this->y = y; this->r = r;
  18.         }
  19.        
  20.         int cont(Circulo* other) {
  21.             float d_centros = sqrt( pow((this->x - other->x), 2) + pow((this->y - other->y), 2));
  22.             if (d_centros == 0)
  23.                 return 0;
  24.             else if (d_centros < this->r - other->r || d_centros > this->r + other->r)
  25.                 return 0;
  26.             else if (d_centros + this->r < other->r || d_centros + other->r < this->r)
  27.                 return 0;
  28.             else if (d_centros == this->r + other->r)
  29.                 return 1;
  30.             else if (d_centros == absoluto(this->r - other->r))
  31.                 return 1;
  32.             else if (d_centros < this->r + other->r)
  33.                 return 2;
  34.             else
  35.                 return 0;
  36.         }  
  37. };
  38.  
  39.  
  40.  
  41. int main() {
  42.     int n;
  43.     cin >> n;
  44.    
  45.    
  46.     Circulo* c[n];
  47.     int contador = 0;
  48.     for (int i = 0; i < n; i++) {
  49.         float x; float y; float r;
  50.         cin >> x; cin >> y; cin >> r;
  51.         c[i] = new Circulo(x, y, r);
  52.        
  53.        
  54.         for (int j = 0; j < i; j++) {
  55.             if (contador > 2*n)
  56.                 break;
  57.             contador += c[i]->cont(c[j]);
  58.         }
  59.        
  60.        
  61.     }
  62.    
  63.     if (contador <= 2*n )
  64.         cout << contador ;
  65.     else
  66.         cout << "greater";
  67.     cout << endl;
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement