Cod sursa(job #2555879)

Utilizator Florinos123Gaina Florin Florinos123 Data 24 februarie 2020 14:47:05
Problema Trapez Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.47 kb
#include <fstream>
#include <algorithm>
#include <cmath>

using namespace std;

ifstream f ("trapez.in");
ofstream g ("trapez.out");

int n, lg;
double panta[1000005];

struct punct {
int x, y;
}v[1005];

void read ()
{
 int i, xx, yy;
 f >> n;
  for (i=1; i<=n; i++)
  {
      f >> xx >> yy;
      v[i].x = xx, v[i].y = yy;
  }
}

void calcpanta ()
{
 int i, j;
 double tangenta, xx, yy;
   for (i=1; i<n; i++)
   {
       for (j=i+1; j<=n; j++)
       {
           xx = v[i].x - v[j].x;
           yy = v[i].y - v[j].y;
            tangenta = yy / xx;
            lg ++, panta[lg] = tangenta;
       }
   }
}

void bubblesort ()
{
  int i, j;
  double aux;
   for (i=1; i<lg; i++)
   {
       for (j=i+1; j<=lg; j++)
       {
           if (panta[i] > panta[j])
           {
               aux = panta[i];
               panta[i] = panta[j];
               panta[j] = aux;
           }
       }
   }
}

void afisare ()
{
 int i, j;
  for (i=1; i<=lg; i++)
    g << panta[i] << " ";
}

void solve ()
{
  int i, j, aux, rez = 0;
   for (i=1; i<=lg; i++)
   {
       if (panta[i] == panta[i+1])
       {
           j = i;
            while (panta[j] == panta[j+1] && j+1 <= lg)
                j ++;
           aux = j-i+1;
          if (aux > 1)
            rez = rez + (((aux-1) * aux)/2);
         i = j;
       }
   }
 g << rez;
}

int main()
{
 read();
 calcpanta();
 bubblesort();
 solve();
    return 0;
}