Tuesday, December 11, 2018

[UVa] 152 - Tree's a Crowd

Author            : Dipu Kumar Mohanto 
                    CSE, Batch - 6
                    BRUR.
Problem Statement : 152 - Tree's a Crowd
Source            : Devskill
Category          : Data Structure
Algorithm         : Two Pointer
Verdict           : Accepted
#include "bits/stdc++.h"
 
using namespace std;
 
#define EPS          1e-7
 
static const int maxn = 1e5 + 5;
 
typedef int T;
 
struct point_3D
{
      T x, y, z;
      point_3D(T x = 0.0, T y = 0.0, T z = 0.0) :
            x(x), y(y), z(z) {}
      inline T dist(const point_3D &p) const
      {
            T xx = (x - p.x) * (x - p.x);
            T yy = (y - p.y) * (y - p.y);
            T zz = (z - p.z) * (z - p.z);
            return sqrt(xx + yy + zz);
      }
} points[maxn];
 
int cnt[10];
 
int main()
{
      int n = 0;
      int x, y, z;
      while (scanf("%d %d %d", &x, &y, &z) == 3)
      {
            if (x == 0 && y == 0 && z == 0) break;
            points[++n] = point_3D(x, y, z);
      }
      for (int i = 1; i <= n; i++)
      {
            int k = 12;
            for (int j = 1; j <= n; j++)
            {
                  if (i == j) continue;
                  int dist = points[i].dist(points[j]);
                  if (dist < k) k = dist;
            }
            if (k < 10) cnt[k]++;
      }
      for (int i = 0; i < 10; i++) printf("%4d", cnt[i]);
      puts("");
}
 
 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.