Cod sursa(job #7019)

Utilizator mithyPopovici Adrian mithy Data 21 ianuarie 2007 11:49:26
Problema Pachete Scor 0
Compilator cpp Status done
Runda preONI 2007, Runda 1, Clasa a 10-a Marime 1.09 kb
#include <fstream.h>
#include <math.h>

void read();
void make();
void write();

struct punct
{
   int x;
   int y;
   int dist;
}a[100],s;
int n,max;

int main()
{
   read();
   make();
   write();

   return 0;
}

void read()
{
   int i;
   ifstream fin("pachete.in");
   fin >> n;
   fin >> s.x >> s.y;

   for (i=0; i<n; i++)
       fin >> a[i].x >> a[i].y;
}

void make()
{
   int i,j,maxDist=0;
   for (i=0; i<n; i++)
   {
      a[i].dist = abs(s.x-a[i].x) + abs(s.y-a[i].y);
      if (a[i].dist > maxDist) maxDist = a[i].dist;
   }

   for (i=0; i<n; i++)
   {
      if (a[i].dist == maxDist)
      {
         a[i].dist = -1;
         max++;
      }
   }

   for (i=0; i<n-1; i++)
   {
      if (a[i].dist==-1) continue;
      for (j=i+1; j<n; j++)
      {
         if (a[j].dist==-1) continue;

         if ( (a[i].dist + a[j].dist) <= maxDist )
         {
            a[i].dist = -1;
            a[j].dist = -1;
            max++;
         }
      }
   }
}

void write()
{
   ofstream fout("pachete.out");
   fout << max << '\n';
}